Word 2007VBA:change wdHeaderFooterPrimary fails for .dotm, ok for

D

dpomt

I am using the VBA code below two insert different pictures on first page
header and primary header.
This codes works pretty fine in Word 2003 and also in Word 2007 as long as
document is either not saved or daved as .doc or .dot. As soon as I save the
document as .docm/.docm, the code works incorrect: the second picture is not
inserted on second page (primarypage) as intended but also on first page.


---
Dim oSec As Section
Dim r1 as Range
Dim r2 as Range
Dim hfFirstPage As HeaderFooter
Dim hfPrimaryPage As HeaderFooter

Set oSec = ActiveDocument.Sections(1)
Set hfFirstPage = oSec.Headers(wdHeaderFooterFirstPage)
Set hfPrimaryPage = oSec.Headers(wdHeaderFooterPrimary)

Set r1 = hfFirstPage.Shapes.AddPicture(FileName:=strImageWithPath1,
LinkToFile:=True, SaveWithDocument:=False)
Set r2 = hfPrimaryPage.Shapes.AddPicture(FileName:=strImageWithPath2,
LinkToFile:=True, SaveWithDocument:=False)
....
---

Right now, I am using the workaround to save my document as .doc. But this
will not let me store word 2007 specialities in the document.
Any suggestions what goes wrong in .docm/.dotm with my code?
I have found other posts describing exactly that behavior but no solution
was presented.

Any suggestion?
Thanks,
dpomt.
 

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