Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Auto Split/Save document into multiple documents - Is this possibl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abqhusker - 03 Aug 2006 21:20 GMT
E.g. 100 page document that I want to save into 10 separate files of 10 pages
each.  File 1 - pages 1 thru 10, File 2 - pages 11 thru 20, etc.  Is there an
easy way to do this kind of thing?  Any help would be appreciated greatly
Doug Robbins - Word MVP - 03 Aug 2006 21:57 GMT
Pages (particularly a multiple number of pages) are not a very good thing to
be using as a basis.  If there was some other way of determining the split
point, such as a section break, the result would be more repeatable.  You
could modify the following code to do it:

Sub splitter()

'

' splitter Macro

' Macro created 16-08-98 by Doug Robbins to save each page of a document

' as a separate file with the name Page#.DOC

'

Dim Counter As Long, Source As Document, Target As Document

Set Source = ActiveDocument

Selection.HomeKey Unit:=wdStory

Pages = Source.BuiltInDocumentProperties(wdPropertyPages)

Counter = 0

While Counter < Pages

   Counter = Counter + 1

   DocName = "Page" & Format(Counter)

   Source.Bookmarks("\Page").Range.Cut

   Set Target = Documents.Add

   Target.Range.Paste

   Target.SaveAs FileName:=DocName

   Target.Close

Wend

End Sub

The following is an untested modification of the above that might do it

Dim Counter As Long, Source As Document, Target As Document

Dim i as Long, mypage as range

Set Source = ActiveDocument

Selection.HomeKey Unit:=wdStory

Pages = Source.BuiltInDocumentProperties(wdPropertyPages)

Counter = 0

While Counter < Pages

   Counter = Counter + 10

   DocName = "Page" & Format(Counter - 9)

   Source.Bookmarks("\Page").Range.Cut

   Set Target = Documents.Add

   Target.Range.Paste

   For i = 1 to 9

           Set mypage =     Source.Bookmarks("\Page").Range

           Target.Range.InsertAfter mypage

           Source.Bookmarks("\Page").Range.Cut

    Next i

   Target.SaveAs FileName:=DocName

   Target.Close

Wend

It should number the separate files as Page1, Page11, Page21, etc.

If you had section breaks, you could use:

Sub splitter()
' splitter Macro
' Macro created by Doug Robbins to save each letter created by a mailmerge
' as a separate file, retaining the header and footer information.
Dim i As Long, Source As Document, Target As Document, Letter As Range
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count
   Set Letter = Source.Sections(i).Range
   Set Target = Documents.Add
   Target.Range = Letter
   Target.Sections(2).PageSetup.SectionStart = wdSectionContinuous
   Target.SaveAs FileName:="Letter" & i
   Target.Close
Next i
End Sub

Signature

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

> E.g. 100 page document that I want to save into 10 separate files of 10
> pages
> each.  File 1 - pages 1 thru 10, File 2 - pages 11 thru 20, etc.  Is there
> an
> easy way to do this kind of thing?  Any help would be appreciated greatly
abqhusker - 03 Aug 2006 22:58 GMT
Thanks, Doug.  I will test out the codes tonight.  I appreciate your
expertise immensely.

Ed

> Pages (particularly a multiple number of pages) are not a very good thing to
> be using as a basis.  If there was some other way of determining the split
[quoted text clipped - 110 lines]
> > an
> > easy way to do this kind of thing?  Any help would be appreciated greatly
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.