Do While Not End of File

L

LHernon

I need to write a macro that will go down through a Word
document page by page and copy each page out to a new
document of its own.

I have started the macro and can get it to copy the
current page out to a new document but I do not know how
to tell it to repeat the process until it gets to the end
of the document.

Does a macro for this type of thing already exist or can
someone tell me how to include a Do While ... statement in
my macro please.

Thanks.
 
J

Jonathan West

The technique required varies a bit depending on how you are working your
way through the file. If you provide the code you have so far, it will be
much easier to see how the loop needs to be set up.
 
D

Doug Robbins - Word MVP

Hi Linda.

Here's a macro that will do that:

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 Pages as Integer, Counter as Integer, DocName as String
Selection.HomeKey Unit:=wdStory
Pages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
Counter = Counter + 1
DocName = "Page" & Format(Counter)
ActiveDocument.Bookmarks("\Page").Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
Wend

End Sub

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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