import a header

A

Antonhino

Good morning
I would like to import a header to a word document from the macro of
another word document.
Thank you.
 
D

Doug Robbins - Word MVP

I am not really sure what you want to do, but the following will create a
new document and insert into it the header of the activedocument.

Dim source As Document, target As Document, hrange As Range
Set source = ActiveDocument
Set target = Documents.Add
Set hrange = source.Sections(1).Headers(wdHeaderFooterPrimary).Range
hrange.End = hrange.End - 1
target.Sections(1).Headers(wdHeaderFooterPrimary).Range = hrange


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Antonhino

Thanks for your answer,
but in fact, I want to insert the header of an existing document into
the active document.

Antonhino
 
D

Doug Robbins - Word MVP

In that case you would use:

Dim source As Document, target As Document, hrange As Range
Set target = ActiveDocument
Set source = Documents.Open("path\filename")
Set hrange = source.Sections(1).Headers(wdHeaderFooterPrimary).Range
hrange.End = hrange.End - 1
target.Sections(1).Headers(wdHeaderFooterPrimary).Range = hrange


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

Antonhino

In fact it works well for the text, but it doesn't import pictures.
What should I do.
Thanks.
 
D

Doug Robbins - Word MVP

It may be easier to consider another approach. Open the document with the
required Header, replace all the text in it with the text in the document in
which you want the header and save it with a new name.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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