Is there a way to save every page of a document as individual documents? I need to send different pages of a report to different people! Help
Is there a way to save every page of a document as individual documents? I need to send different pages of a report to different people! Help
Hi, Tricia! Welcome!
What separates them? Page breaks? Section breaks?
~Anne Troy
See if Cindy Meister's method is helpful, and let us know how it works out, or tell us what's wrong. Make sure you do any testing on a COPY of your file.
http://homepage.swissonline.ch/cindy...q2.htm#SepFile
~Anne Troy
Ok, here's a small method that will separate a document based on sections, so make sure you have section breaks in position. The subdocuments will be saved just where the main document is, they have the same name + a number for each section:
[VBA]
Sub BreakIt()
Dim MainDoc As Document, SubDoc As Document, SectionNo%, sPath$
Set MainDoc = ActiveDocument
sPath = MainDoc.Path
If Right(sPath, 1) <> "\" Then sPath = sPath & "\"
For SectionNo = 1 To ActiveDocument.Sections.Count
ActiveDocument.Sections(SectionNo).Range.Copy
Set SubDoc = Application.Documents.Add
SubDoc.Range.Paste
SubDoc.SaveAs sPath & Left(MainDoc.Name, Len(MainDoc.Name) - 4) & _
SectionNo & ".doc"
SubDoc.Close
Next SectionNo
Set SubDoc = Nothing
Set MainDoc = Nothing
End Sub
[/VBA]
Why does my code look so messy?? I did not add the indention on the lines beginning with SubDoc!! Could it be the that SubDoc contains the keyword Sub???
Must be a fluke. I'll have mark007 have a look.
~Anne Troy
Spot on, is the fact the line starts with the word Sub. I can fix it though. Will sort it now!
"Computers are useless. They can only give you answers." - Pablo Picasso
Mark Rowlinson FIA | The Code Net
Can this work using pages and not sections? There are no section breaks in this Document. Help!
Are there manual page breaks, Tricia? Or are the pages broken by use of formatting styles?
Also, if there ARE manual page breaks, you can quickly turn them into section breaks using Find/Replace. Just hit Ctrl+H and then the More and Special buttons to find the way to do that. It would be quicker to do that than to rewrite the code (Maybe!). LOL
Let me know if you have difficulty...
~Anne Troy
They are not manual. The report is actually EFT advices from our accounting software that I want to e-mail to people. Any more sugestions? please
Well...in order to break the documents up, we need to know where they stop and start. For instance, is there some text at the top of the document that's unique? Suppose it says "Financial Report for ... " at the top of every page. Then, you can simply do a find/replace. Find "Financial Report for" and replace it with a section break and the same words. Understand?
Then, once you have a section break for each document, you should be able to use the macro.
If you don't understand or can't work it out, let us know the basic layout of your file. We can't guess.
~Anne Troy
Any luck, Tricia?
~Anne Troy
No need to bother messing around with Sections if all you want is Pages.
It is possible, using either Gotos, or the Browser, to move through a document a page at a time. It is possible in code to Select the current page using the built-in bookmark, "\Page".
That should be all you need to know. Here's some code based on it ..
[vba]Sub SavePages()
Dim MainDoc As Document, PageDoc As Document
Dim lPageNo As Long
Dim strNameStem As String
Set MainDoc = ActiveDocument
strNameStem = Left(MainDoc.FullName, Len(MainDoc.FullName) - 4)
lPageNo = 1
Application.Browser.Target = wdBrowsePage
Application.ScreenUpdating = False
MainDoc.Range(0, 0).Select
Do
Selection.Bookmarks("\Page").Select
Selection.Copy
Set PageDoc = Application.Documents.Add
PageDoc.Range.Paste
PageDoc.SaveAs strNameStem & " - Page " & lPageNo & ".doc"
PageDoc.Close
If lPageNo = MainDoc.Range.Information(wdNumberOfPagesInDocument) Then _
Exit Do
Application.Browser.Next
lPageNo = lPageNo + 1
Loop
Application.ScreenUpdating = True
Set PageDoc = Nothing
Set MainDoc = Nothing
End Sub[/vba]
I must just say that when I tested this the screen was flashing an awful lot - I'll play with it and get it sorted. Meanwhile it should do the job for you.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Well, I don't understand why Application.ScreenUpdating isn't suppressing things, but this runs a little cleaner ..
[vba]Sub SavePages()
Dim MainDoc As Document, PageDoc As Document
Dim lPageNo As Long
Dim strNameStem As String
Set MainDoc = ActiveDocument
strNameStem = Left(MainDoc.FullName, Len(MainDoc.FullName) - 4)
lPageNo = 1
Application.ScreenUpdating = False
MainDoc.Range(0, 0).Select
Do
Selection.Bookmarks("\Page").Select
Selection.Copy
Set PageDoc = Application.Documents.Add(Visible:=False)
PageDoc.Range.Paste
PageDoc.SaveAs strNameStem & " - Page " & lPageNo & ".doc"
PageDoc.Close
If lPageNo = MainDoc.Range.Information(wdNumberOfPagesInDocument) Then _
Exit Do
Selection.GoToNext wdGoToPage
lPageNo = lPageNo + 1
Loop
Application.ScreenUpdating = True
Set PageDoc = Nothing
Set MainDoc = Nothing
End Sub[/vba]
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
So, instructions:
If I have that right, we can make it a kbase entry.
- Open the document.
- Hit Alt+F11 to get to the VB Editor (VBE).
- From the menu, choose Insert-Module.
- Paste the code above into the window at right.
- Hit the save diskette icon.
- Close the VBE with the X.
- Go to Tools-Macro-Macros and double-click on "SavePages".
~Anne Troy
You have it almost right
I wouldn't include #5 - not without comment anyway. For all sorts of reasons the User might not want to save the Document at that point, but they need to understand that the code is part of the document and if they don't save it, it won't be there next time they open the document. Depending on what the code is they might want to put it in a Template rather than the Document.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Thanks, Tony!
~Anne Troy
Tony...so this code needs manual page breaks or not?
Sorry. I want to add it to the kbase...
I'll put your name on it, if it's cool with you.
~Anne Troy
I'm cool.
No manual page breaks, or anything else special needed; it works on any document as is. The built-in bookmark gives you the current page (including any trailing pagebreak); only downside I see is that it only works with the Selection - you can't use it on a different Range.
Don't know what happenned to the half-submission I did last weekend, but I've got an almost complete version of that to submit as well - I got a bit sidetracked (hard to believe, I know) writing some instructions and will probably end up with an article about navigating the VBE as well.
Enjoy,
Tony
---------------------------------------------------------------
Give a man a fish and he'll eat for a day.
Teach him how to fish and he'll sit in a boat and drink beer all day.
I'm (slowly) building my own site: www.WordArticles.com
Great. I've got another question I'm about to post.
~Anne Troy