Solved

Split document based on page breaks

Posted on 2013-06-12
2
739 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
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…
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.

707 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