Inserting headers from another template

A

Adrian

Hi all,

I have a wish to programatically insert the contents of
the headers (including images) from another template into
certain headers in a multi-section document.

It would run like this:-

Insert into section 1 header the contents of the header
in Template x

Insert into section 2 header the contents of the header in
Template y

Can anyone tell me if this possible?

It would be cool to import the header sizes too.

I have checked some of the postings on this site and they
seem to recommend looking at:-
http://www.mvps.org/word/FAQs/MacrosVBA/FindReplaceAllWithV
BA.htm
But this doesnt help me much with my specific requirement.

Any suggestions on coding would be most apprciated.

many thanks

Adrian
 
M

Mark Tangard

Adrian,

Here's a way to do it with one header (the primary header)
in one section. I'll leave to you the gyrations needed to
handle even-page/first-page headers and to match Section 2
to Template Y, etc.

Note that this copies text, images, and manual formatting,
but you may end up having to tweak the code to match the
content exactly if the base styles aren't the same in both
files. For example, the 'Header' style typically based on
Normal, so if, say, the Normal style in the source template
is set to, say, Tahoma font but it's Times New Roman in the
target doc, any non-manually formatted text in the source
template will import in Times but anything you've re-fonted
manually in the source template will arrive in that font --
SORT OF. (I've had this kind of thing import the text with
the inverse of the original font attributes, esp. when the
header contains mixed bold and nonbold text.)

--
Mark Tangard <[email protected]>, Microsoft Word MVP
Please reply only to the newsgroup, not by private email.
Note well: MVPs do not work for Microsoft.
"Life is nothing if you're not obsessed." --John Waters


Dim theTemplate As Document, theDoc As Document
Set theDoc = ActiveDocument
Set theTemplate = Documents.Open("C:\Path\SourceTemplate.dot")
With theDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range
.FormattedText = theTemplate.Sections(1). _
Headers(wdHeaderFooterPrimary). _
Range.FormattedText
.Characters.Last.Delete 'Toss leftover paragraph mark
End With
theTemplate.Close 0
theDoc.Activate
 

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