Hi all,
I have inherited a macro that copies the headers and footers between documents (this is done as our company is multi-site and sometimes a file gets assigned to another office and they want to take an existing doc and "swap" in programmatically the headers/footers
for the new office).
Here are the details:
- different first page header/footer from the rest of the doc
so the macro fires and here is framework of the code:
- open up a blank doc using the template for the new location (e.g. "Halifax_LtrHd.dot") as a new doc; this will be the "source" for the header/footer info
- switch back and forth between the "original" doc and the new doc copying the headers/footers
The previous guy just recorded the macro. I am slimming it down and trying to make it more bullet proof.
The question: I found that the "source" document needs to have a section break added to the bottom of it in order to "reveal" the header and footer for the 2nd page onward. Same goes for the "target" document - if it does not have more than one page, I have
to go to the bottom and add a section break to force a second page. So is there any other way to get to this "data" without "brute force" copying and pasting.
The code now looks something like this:
' change to the new document to pick up the header info from the new doc
Application.Documents(lcNewDoc).Activate
' open up the header
ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageHeader
' select the whole "story" i.e. everything in the header and copy it
Selection.WholeStory
Selection.Copy
' activate the original document and open it's header
Application.Documents(lcOriginalDoc).Activate
ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageHeader
' select that entire header (to paste over); this seems to add one paragraph marker so delete that
With Selection
.WholeStory
.PasteAndFormat (wdPasteDefault)
.Delete (wdCharacter)
End With
This is what I would call brute force programming - basically doing what the person would do manually. It uses the Selection object to move stuff around. Is there a way to get at the header/footer data without doing this - perhaps through some other objects?
Thanks,
Albert Gostick