Copy a page to a new document

W

Wespa

Hi.
I've test the code below but it "forgets" the header and footer.
How could i fix that?
Sub BreakOnPage()
' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage

For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")

'Select and copy the text to the clipboard
ActiveDocument.Bookmarks("\page").Range.Copy

' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace
ChangeFileOpenDirectory "C:\"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close

' Move the selection to the next page in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
 
J

Jean-Guy Marcil

Wespa was telling us:
Wespa nous racontait que :
Hi.
I've test the code below but it "forgets" the header and footer.
How could i fix that?

Header/Footer info are stored in section breaks, or the last ¶ in the
document if there aren't any actual section breaks.
Word is not designed to handle pages and lines. It is always messy when you
want to work with a page as if it was a PowerPoint slide. The header is in
fact an entity that spans many pages.

Here is one idea:
What I would do is figure out which page # in the current section I want to
copy, copy the whole section including the section break (or last ¶)and then
delete all the pages before and after the target page making sure the
section break is left alone (you may have to convert the section break from
Next Page to Continuous...).

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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