?
Solved

Saving one file per page in Word

Posted on 2003-02-27
6
Medium Priority
?
367 Views
Last Modified: 2008-03-17
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
Comment
Question by:rfeeman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:MacroWizard
ID: 8041299
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
 

Author Comment

by:rfeeman
ID: 8041623
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
 
LVL 1

Accepted Solution

by:
MacroWizard earned 200 total points
ID: 8041841
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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

Author Comment

by:rfeeman
ID: 8042211
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
 
LVL 1

Expert Comment

by:MacroWizard
ID: 8042541
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
 

Author Comment

by:rfeeman
ID: 8043996
Thank you so much for such a timely and effective answer!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . If you have responsibility for software in production, I bet you’d like to know more about it. I don’t mean that you’d like an extra peek into the bowels of the sourc…
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
This video shows how use content aware, what it’s used for, and when to use it over other tools.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question