How to Break Up LARGE Word Document By Page Range

S

Shiraz

I am looking at this article in the knowledge base :

http://support.microsoft.com/kb/306348

And I am attempting to break up this very large word document into smaller
files with page range of 50 pages for example.

Since I am new to this sort of programming I would appreciate any help. Also
pointing to any resources would be cool.

This is how far I have gotten with the help of the above KB article:
Sub ExtractSections()
'
' ExtractSections Macro
'

' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage

For i = 3 To 5
' ActiveDocument.BuiltInDocumentProperties("Number of Pages")
'Select and copy the text to the clipboard.
ActiveDocument.Bookmarks("\page").Range.Copy
' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace

' Move the selection to the next page in the document.
Application.Browser.Next
Next i
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close
ActiveDocument.Close savechanges:=wdDoNotSaveChanges


End Sub

I know little about this API. I am taking a sample document and WANTED to
extract pages between the range 3-5 from it. This is incorrectly implemented
ofcourse.
 
D

Doug Robbins - Word MVP

The following should do it:

Dim Counter As Long, Pages As Long
Dim SourceDoc As Document, TargetDoc As Document
Dim Source As Range, Target As Range
Set SourceDoc = ActiveDocument
Selection.HomeKey Unit:=wdStory
Pages = SourceDoc.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
Counter = Counter + 1
DocName = "c:\test\Pages " & Format(Counter) & " to " & Format(Counter +
50)
Set TargetDoc = Documents.Add
For i = 1 To 50
Set Target = TargetDoc.Range
Target.Collapse wdCollapseEnd
SourceDoc.Activate
Set Source = SourceDoc.Bookmarks("\Page").Range
Target.FormattedText = Source.FormattedText
Source.Delete
Next i
TargetDoc.SaveAs filename:=DocName
TargetDoc.Close
Counter = Counter + 50
Wend
SourceDoc.Close wdDoNotSaveChanges


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Jeff Kirk

How would I break up a 200+ page document into 200+ documents each consisting of the individual pages of the 200+ document?
Thanks in advance



Shira wrote:

How to Break Up LARGE Word Document By Page Range
25-Jul-08

I am looking at this article in the knowledge base :

http://support.microsoft.com/kb/30634

And I am attempting to break up this very large word document into smaller
files with page range of 50 pages for example.

Since I am new to this sort of programming I would appreciate any help. Also
pointing to any resources would be cool.

This is how far I have gotten with the help of the above KB article:
Sub ExtractSections(

' ExtractSections Macr


' Used to set criteria for moving through the document by page
Application.Browser.Target = wdBrowsePag

For i = 3 To
' ActiveDocument.BuiltInDocumentProperties("Number of Pages"
'Select and copy the text to the clipboard
ActiveDocument.Bookmarks("\page").Range.Cop
' Open new document to paste the content of the clipboard into
Documents.Ad
Selection.Past
' Removes the break that is copied at the end of the page, if any
Selection.TypeBackspac

' Move the selection to the next page in the document
Application.Browser.Nex
Next
ChangeFileOpenDirectory "C:\
DocNum = DocNum +
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc
ActiveDocument.Clos
ActiveDocument.Close savechanges:=wdDoNotSaveChange

End Su

I know little about this API. I am taking a sample document and WANTED to
extract pages between the range 3-5 from it. This is incorrectly implemented
ofcourse.

Previous Posts In This Thread:

How to Break Up LARGE Word Document By Page Range
I am looking at this article in the knowledge base :

http://support.microsoft.com/kb/30634

And I am attempting to break up this very large word document into smaller
files with page range of 50 pages for example.

Since I am new to this sort of programming I would appreciate any help. Also
pointing to any resources would be cool.

This is how far I have gotten with the help of the above KB article:
Sub ExtractSections(

' ExtractSections Macr


' Used to set criteria for moving through the document by page
Application.Browser.Target = wdBrowsePag

For i = 3 To
' ActiveDocument.BuiltInDocumentProperties("Number of Pages"
'Select and copy the text to the clipboard
ActiveDocument.Bookmarks("\page").Range.Cop
' Open new document to paste the content of the clipboard into
Documents.Ad
Selection.Past
' Removes the break that is copied at the end of the page, if any
Selection.TypeBackspac

' Move the selection to the next page in the document
Application.Browser.Nex
Next
ChangeFileOpenDirectory "C:\
DocNum = DocNum +
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc
ActiveDocument.Clos
ActiveDocument.Close savechanges:=wdDoNotSaveChange

End Su

I know little about this API. I am taking a sample document and WANTED to
extract pages between the range 3-5 from it. This is incorrectly implemented
ofcourse.

Re: How to Break Up LARGE Word Document By Page Range
The following should do it

Dim Counter As Long, Pages As Lon
Dim SourceDoc As Document, TargetDoc As Documen
Dim Source As Range, Target As Rang
Set SourceDoc = ActiveDocumen
Selection.HomeKey Unit:=wdStor
Pages = SourceDoc.BuiltInDocumentProperties(wdPropertyPages
Counter =
While Counter < Page
Counter = Counter +
DocName = "c:\test\Pages " & Format(Counter) & " to " & Format(Counter +
50
Set TargetDoc = Documents.Ad
For i = 1 To 5
Set Target = TargetDoc.Rang
Target.Collapse wdCollapseEn
SourceDoc.Activat
Set Source = SourceDoc.Bookmarks("\Page").Rang
Target.FormattedText = Source.FormattedTex
Source.Delet
Next i
TargetDoc.SaveAs filename:=DocName
TargetDoc.Close
Counter = Counter + 50
Wend
SourceDoc.Close wdDoNotSaveChanges


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP



Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF GridView Sample To Insert, Update, and Delete Records
http://www.eggheadcafe.com/tutorial...a-c9a46fd3aeb2/wpf-gridview-sample-to-in.aspx
 

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