Solved

Split document based on page breaks

Posted on 2013-06-12
2
695 Views
Last Modified: 2013-06-12
Dear Experts:

I got a huge word document with lots of page breaks (Strg + Enter) .

Is it possible to split this document based on the page breaks, i.e. ...

If a document has got 4 page breaks, this document gets split based on these page breaks and saved individually, i.e. 5 different documents, named doc1 till doc5 are created and saved.

I hope this is feasible and does not require too much coding work.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39241067
Hi

pls refer to http://www.extendoffice.com/documents/word/966-word-split-document-into-multiple-documents.html

Sub SplitIntoPages() 
Dim docMultiple As Document 
Dim docSingle As Document 
Dim rngPage As Range 
Dim iCurrentPage As Integer 
Dim iPageCount As Integer 
Dim strNewFileName As String 
Application.ScreenUpdating = False 'Makes the code run faster and reduces screen _
flicker a bit. 
Set docMultiple = ActiveDocument 'Work on the active document _
(the one currently containing the Selection) 
Set rngPage = docMultiple.Range 'instantiate the range object
iCurrentPage = 1 
'get the document's page count
iPageCount = docMultiple.Content.ComputeStatistics(wdStatisticPages) 
Do Until iCurrentPage > iPageCount 
If iCurrentPage = iPageCount Then 
rngPage.End = ActiveDocument.Range.End 'last page (there won't be a next page) 
Else
'Find the beginning of the next page
'Must use the Selection object. The Range.Goto method will not work on a page
Selection.GoTo wdGoToPage, wdGoToAbsolute, iCurrentPage + 1 
'Set the end of the range to the point between the pages
rngPage.End = Selection.Start 
End If 
rngPage.Copy 'copy the page into the Windows clipboard
Set docSingle = Documents.Add 'create a new document
docSingle.Range.Paste 'paste the clipboard contents to the new document
'remove any manual page break to prevent a second blank
docSingle.Range.Find.Execute Findtext:="^m", ReplaceWith:="" 
'build a new sequentially-numbered file name based on the original multi-paged file name and path
strNewFileName = Replace(docMultiple.FullName, ".doc", "_" & Right$("000" & iCurrentPage, 4) & ".doc") 
docSingle.SaveAs strNewFileName 'save the new single-paged document
iCurrentPage = iCurrentPage + 1 'move to the next page
docSingle.Close 'close the new document
rngPage.Collapse wdCollapseEnd 'go to the next page
Loop 'go to the top of the do loop
Application.ScreenUpdating = True 'restore the screen updating 
'Destroy the objects.
Set docMultiple = Nothing 
Set docSingle = Nothing 
Set rngPage = Nothing 
End Sub 

Open in new window

Regards
0
 

Author Closing Comment

by:AndreasHermle
ID: 39242644
Great help. thank you very much for your professional help.

Regards, Andreas
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

786 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