Strange HeaderFooter behavior Word 2007

R

rick

Something is strange with HeadersFooters in Word 2007. I simply need to add an
image to the PRIMARY header of a document (not the First Page Header). The
following code should do this.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"c:\mypic.jpg", False, True

Instead, though, the image is added to the FirstPage header. It doesn't seem to
matter whether the Different First Page attribute is on or off in Page Setup.
It seems as though Word no longer knows the difference between a First Page and
Primary header/footer.

Strangely, this only occurs with documents in the new 2007 format (.docm and
..docx). It works perfectly and exactly as it should in .doc documents in
compatibility mode as well, of course, in Word 97/2K/XP/2003. That is, the
image is added to the Primary header.

Can anyone else duplicate this strangeness?

Thanks. Rick.
 
J

Jay Freedman

Something is strange with HeadersFooters in Word 2007. I simply need to add an
image to the PRIMARY header of a document (not the First Page Header). The
following code should do this.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"c:\mypic.jpg", False, True

Instead, though, the image is added to the FirstPage header. It doesn't seem to
matter whether the Different First Page attribute is on or off in Page Setup.
It seems as though Word no longer knows the difference between a First Page and
Primary header/footer.

Strangely, this only occurs with documents in the new 2007 format (.docm and
.docx). It works perfectly and exactly as it should in .doc documents in
compatibility mode as well, of course, in Word 97/2K/XP/2003. That is, the
image is added to the Primary header.

Can anyone else duplicate this strangeness?

Thanks. Rick.

Yes, I can duplicate it. I think we can honestly change its designation from
"strangeness" to "bug".

Interestingly, the behavior changes to the correct one in the _same_ document if
I save it in Word 2003 format. When I save that document again in Word 2007
format, the behavior goes wrong again.

I'll report it and quote your post.
 
T

Tony Jollans

On a quick look it appears you are correct. How odd.

I will try and look at this properly later.
 
J

Jay Freedman

Yes, I can duplicate it. I think we can honestly change its designation from
"strangeness" to "bug".

Interestingly, the behavior changes to the correct one in the _same_ document if
I save it in Word 2003 format. When I save that document again in Word 2007
format, the behavior goes wrong again.

I'll report it and quote your post.

After some discussion with other Word MVPs, we've come up with a workaround. It
involves inserting the picture as an InlineShape and then converting it to a
Shape. This works in Word 2007 format documents but not in earlier versions:

Sub demo()
Dim oILS As InlineShape
Dim oShp As Shape

With ActiveDocument.Sections.First.Headers(wdHeaderFooterPrimary)
Set oILS = .Range.InlineShapes.AddPicture("c:\mypic.jpg", False, True)
End With

Set oShp = oILS.ConvertToShape
With oShp ' the following is optional
.WrapFormat.Type = wdWrapTopBottom
.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
.Left = 0
.Top = 0
End With
End Sub
 
S

Summer

I don't have a problem with First Page Different and Odd/Even it puts in
the Graphic on page 1 only - just delete "False, True"" works fine.

Whereas with yours Jay I have problems with the With
..Wrap
..xxx
..xxxx etc
in the macro?
 
J

Jay Freedman

"I have problems" doesn't give me anything to go on. What happens? Error
message? Macro stops with a line highlighted (if so, which one)? Picture not
formatted as desired?
 
S

Summer

I wasn't actually asking for help Jay - I just made a remark that the
original line of code works in 2007 for me.

Just a little busy if I don't work it out I'll ask - thank you.
 
M

me

Thanks so much Jay. This workaround works for me. I honestly never even thought
of converting to an InLineShape first.

Rick
 
G

Greg Maxey

Jay,

I don't know if you noticed this or if its worth mentioning, but if
you run Rick's line of code on a new document and then format the
section with different FirstPage different Odd/Even pages, the graphic
remains in the primary header.
 
M

me

I, too, noticed this the other day before I posted.

What I'm doing is placing, sizing and positioning--right-flush--a corporate
logo in the First Page header, then a smaller version of that logo in the
Primary header, and it all has to be done on-the-fly thru VBA. When I attempted
to use VBA to toggle the Different First Page attribute, the results were all
over the place even though when doing it manually, it seemed to work. Most
times, the VBA errored for some reason but not if I stepped thru it. But when I
stepped through it, the positioning would refuse to execute correctly. It did
work thru VBA IF I commented out the first part (placing the main logo on the
First Page header). But when both those routines ran, the results were too
strange. That's when I decided to come here to see if I was spinning wheels for
nothing.

Rick
 

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