[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

Saving one file per page in Word

I have a 25 page Word file that I would like to save as 25 separate Word files, similar to the way the save as HTML feature works. Aside from tediously saving one page at a time, is there a way to automatically save each page as a separate Word document?
0
rfeeman
Asked:
rfeeman
  • 3
  • 3
1 Solution
 
MacroWizardCommented:
You can use VBA. Here is some code.

sub test()
Selection.Bookmarks.Add Name:="TEMP", Range:=Selection.Range
For i = 1 To Selection.Information(wdNumberOfPagesInDocument)
    Selection.GoTo What:=wdGoToPage, Count:=i
    ActiveDocument.Bookmarks("\Page").Select
    If Selection.Information(wdActiveEndPageNumber) <> Selection.Information(wdNumberOfPagesInDocument) Then
        Selection.MoveLeft Unit:=wdCharacter, Extend:=wdExtend
    End If
    ActiveDocument.SaveAs FileName:="C:\" & i & ".doc"
Next

With Selection.Bookmarks("TEMP")
    .Select
    .Delete
End With

End sub

This code will highlight each page and save it to the C drive (the root, change the directory as appropriate). The file name will be the pagenumber + .doc. This method saves each page separately but does not alter the original document. The original document will still have all of its original pages.

If you are unfamiliar with VBA and how to get it in your document. Let us know.
0
 
rfeemanAuthor Commented:
Thank you, I really appreciate the quick response. However the macro did not work quite as well as expected. It did produce 25 files, but each one was a full 25 page copy of the original. Additionally, the macro terminated with the following error code on the final section of code where it tries to delete the bookmark. Subsequently, there is an extraneous bookmark in each of the 25 files.

Run-time error: 5941    The requested member of the collection does not exist.

I would greatly appreciate your continued help in working out the bugs in the macro as we are certainly on the rtight track and are almost there. I can email you a copy of the word file if needed.

Thanks again.
0
 
MacroWizardCommented:
Small detail, small detail! :> I was adapting some code I had created yesterday for printing pages in a file separately so missed the selection thing since part of a print command is the current page. You may have to change some margins etc.

Here ya go...

Sub PrintEachPageSeparately()
' gather info
strFileName = ActiveDocument.Name
ActiveDocument.Bookmarks.Add Name:="temp", Range:=Selection.Range
Selection.Bookmarks.Add Name:="TEMP", Range:=Selection.Range

For i = 1 To Selection.Information(wdNumberOfPagesInDocument)
   Selection.GoTo What:=wdGoToPage, Count:=i
   ActiveDocument.Bookmarks("\Page").Select
   If Selection.Information(wdActiveEndPageNumber) - 1 <> Selection.Information(wdNumberOfPagesInDocument) Then
       Selection.MoveLeft Unit:=wdCharacter, Extend:=wdExtend
   End If
   Selection.Copy
   Documents.Add Template:= _
        "Normal.dot", NewTemplate:=False, DocumentType:=wdNewBlankDocument
   Selection.Paste
   
   ActiveDocument.SaveAs FileName:="C:\" & i & ".doc"
   ActiveDocument.Close
   Windows(strFileName).SetFocus
Next

' Clean up
With ActiveDocument.Bookmarks("TEMP")
    .Select
    .Delete
End With

End Sub

Hope this helps!
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
rfeemanAuthor Commented:
Again, thanks for the quick response. This time the macro ran better, but it would not run under WindowsNT without commenting out two sections of code. I did get it run run under WindowsXP without modification and it ran great except that now each file consists of a blank page and then the page with the data on it. If we can get that problem fixed, we will be all set. It would also be nice if I could run it under NT. The two pieces of code I had to comment out on NT are:

DocumentType:=wdNewBlankDocument

 Windows(strFileName).SetFocus

I really appreciate your help on this. Thanks again.
0
 
MacroWizardCommented:
We are running Windows 98 so it will be difficult to duplicate some of your issues. However, if you send the file to me, I can try and duplicate the blank first page issue.

linda.duguay@leewood.com
0
 
rfeemanAuthor Commented:
Thank you so much for such a timely and effective answer!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now