Computer Forum Forum Index
Register  FAQ Profile Log in to check your private messages Log in Register 

How to copy text and header and footer from one document to

 
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Thu Nov 22, 2007 7:47 am    Post subject: How to copy text and header and footer from one document to Reply with quote

Hello,

I have a macro that opens a document, selects the text and then copies
it at the top of the active document, which works well to copy the
body text, but I can't work out how to also copy the header and
footer. The header contains an image and the footer text.

Below is what I currently have:

Dim strFileName As String
strFileName = "C:\Fax Header Source.doc"
Documents.Open (strFileName)

Dim rngHeaderText As Range
Set rngHeaderText = ActiveDocument.Content

With rngHeaderText
.Copy
End With

ActiveDocument.Close (wdDoNotSaveChanges)

With ActiveDocument
Selection.HomeKey Unit:=wdStory
End With

Selection.PasteAndFormat (wdPasteDefault)


Any advice on how to also copy the header and footer will be greatly
appreciated!

Regards

Michelle M
Back to top
Google
Sponsor





PostPosted: Thu Nov 22, 2007 7:47 am    Post subject: Advertisement

Back to top
Helmut Weber
Guest





PostPosted: Thu Nov 22, 2007 4:31 pm    Post subject: Re: How to copy text and header and footer from one document Reply with quote

Hi Michelle,

you cannot copy a header or footer to another document,
only the contents of it, and you should be aware of
that pagesetup and sections in your target document
should be the same as in the source document.

You may record something like that in the source doc:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Copy
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

open the target doc, do the same,
except copying but pasting.

There are other ways, but as this is the beginners' group...


HTH
--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Computer Forum Forum Index -> microsoft word vba beginners All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Computer Forum