?
Solved

Macro to slit word document into separate batches.

Posted on 2011-10-20
10
Medium Priority
?
350 Views
Last Modified: 2012-05-12
Hi,

We have a word document that I want to split into batches of 3 pages.

For example if we get in a 147 document we want to split it every 3 pages. So the end result we will have 49 documents which have 3 pages.

The split is always 3 pages and the amount of pages can change all the time.

I need something like a macro that will do this.

Thanks

Luke
0
Comment
Question by:luketr
9 Comments
 
LVL 8

Expert Comment

by:PandaPants
ID: 37000668
Is there a hard page, a section break, or a reliable string of text that marks the beginning or end of each set of three pages? If we're relying on a "soft" page break that occurs naturally, then the pages will break differently depending on the printer, font size, margins, etc., and Word has a hard time predicting the breaks accurately.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37000707
Is this a VBScript question, or is VBA acceptable?
0
 

Author Comment

by:luketr
ID: 37000770
It's a VBScript question.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 76

Expert Comment

by:GrahamSkan
ID: 37000855
And to PandaPant's question? Are the pages defined well enough to be sure that the page splits come where you need them, or is some leeway acceptable?

It may help to post a sample.
0
 

Author Comment

by:luketr
ID: 37000996
I have attached an example of the file, this has only 9 pages but the original file has 147.

Thanks

Luke
0
 

Author Comment

by:luketr
ID: 37001011
0
 

Author Comment

by:luketr
ID: 37001022
I've had to change the file extension to .doc as I’m unable to upload an rtf on this web site.

Thanks

Luke
0
 
LVL 14

Expert Comment

by:Stacy Brown
ID: 37153554
This may work for you.  Though you would need to put some sort of delimiter on each page where you want it to break.

http://www.vbaexpress.com/kb/getarticle.php?kb_id=922
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 37154786
This is an attempt to tailor a solution to fit your sample document.
Sub PageThree()
    Dim rng As Range
    Dim rngStart As Long
    Dim rngEnd As Long
    Dim doc As Document
    Dim d As Integer
    Set rng = ActiveDocument.Range
    Do While True
        With rng.Find
            .Text = "LOFIT Interest: N"
            If .Execute Then
                rngStart = rng.Paragraphs.First.Range.Start
                If .Execute Then
                    rngEnd = rng.Paragraphs.First.Range.Start
                    rng.Start = rngStart
                    rng.End = rngEnd
                Else
                    rng.End = ActiveDocument.Range.End
                End If
                Set doc = Documents.Add
                rng.Copy
                doc.Range.Paste
                d = d + 1
                doc.SaveAs "C:\MyFolder\" & "MyDoc" & d & ".docx"
                doc.Close
                If rng.End = ActiveDocument.Range.End Then
                    Exit Do
                End If
            Else
                Exit Do
            End If
        End With
        rng.Start = rngEnd
        rng.End = ActiveDocument.Range.End
    Loop
End Sub

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question