Splitting document into multiple documents

D

David Mueller

I'm trying to split a single document into multiple documents. Specifically,
each page must be it's own document. I'm savvy with VBA for MS Access - but
these Word objects are killing me.

I've seen examples in the news groups that don't seem to be working for me -
I must be missing something. I can accidentally select the first page (from
code I saw in the group), but not subsequent pages.

I can do a For Next Loop for each page in the document. I can navigate to
each page in the document... I can't seem to select it.

Not sure if I should be using the Select or Range object, or both.

Any help appreciated.
Thanks.
 
D

Doug Robbins

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
--
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
 
D

David Mueller

Fabulous! You got me over the next hurdle, too ... pasting into a new
document!
 

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