Word 2003 Selection or Range Objects

G

Guest

I have a large document of 270 pages. I need to save each page as a separate
rtf file. I tried recording a macro and modifying it to iterate through all
the pages selecting, copying and saving as a new document, but the selection
starting from the beginning of the page using shift & ctrl-pgdn-pgdn would
not select the page when used in the macro (it did fine when using it from
the keyboard). I do not understand how to make the selection in VBA using the
range or selection objects. Any help in how to set the selection for a page
would be much appreciated
 
G

Guest

Hi Lako,

Use this macro:

Sub MakeDocs()
Const strSaveDir As String = "G:\temp"
Dim intN As Integer, strN As String

For intN = 1 To ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
strN = LTrim(Str(intN))

Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=strN
ActiveDocument.Bookmarks("\Page").Select
Selection.Copy

Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=strSaveDir & "\RTFDoc" & strN &
".rtf", _
FileFormat:=wdFormatRTF, AddToRecentFiles:=False
ActiveDocument.Close

Next intN

End Sub

Substitute "G:\temp" for the directory in which yout rtf documents are to be
saved. Be sure your 270 page document is the active document when you run the
macro. The macro creates filenames like "RTFDoc1.rtf", "RTFDoc2.rtf" and so
on. The files are based on Normal dot. If you set the default margins
slightly wider or the default font size somewhat smaller, you prevent
creating a blank second page.

Good luck,
Cooz
 

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