Splitting word document

P

pontellt

I need to split a word document into several seperate documents.
The main document is 1076 pages, but every 2 pages is a "new" document
that I want to split out and save.

I found this code on this group:

Sub ExtractPage()
Dim i As Integer
Dim iNumPages As Integer
Dim sCurrentDoc As String


sCurrentDoc = Activedocument.name
'Get the current document's name
iNumPages = Activedocument.ComputeStatistics(wdStatisticPages)
'Get the number of pages
For i = 1 To iNumPages
'For as many times as there are pages
Selection.GoTo What:=wdGoToPage, which:=wdGoToAbsolute, Count:=i
'Goto pagenumber i
Selection.GoTo What:=wdGoToBookmark, name:="\Page"
'Select this page
Selection.Copy
'Copy the selection
Documents.Add
'Add a new document
Selection.Paste
'Paste
Activedocument.SaveAs FileName:="newdocument" & i
'Save the new document as "newdocument" and the value of the
counter i
Activedocument.Close
'Close this new document
Documents(sCurrentDoc).Activate
'Activate the document where we started from
Next i
End Sub



Problem is, I am new at this and can't figure out how I tell this that
each new document is only 2 pages..

Thanks!
 
J

Jezebel

It would be easier to work with whatever occurs on every second page, to
'cause' the new document: a section break? a heading of a given style?

One you've got that, the approach is to define a range for the section you
want, then copy that into a new document, maybe along these lines ---

Dim pSection as Word.Section

For each pSection in ActiveDocument.Sections
With Documents.Add Template:= ...
.Content.InsertAfter pSection.Range
.Saveas FileName:=....
.Close
End with
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top