Solved

Split document based on page breaks

Posted on 2013-06-12
2
706 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 50

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert .PDF 6 68
Prevent user closing word document opened with VB6 6 78
VBA - If Bookmark = "XXBOOKMARKXX" then 15 40
Need to get a Word Count from a Word file 19 39
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 …
When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

840 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