JN said:
Hi Jean-Guy,
Thank you for your reply. Your right about the first line so I changed it
from true to false. IN word 2007 the logo is inserted on all pages but in
2003 the logo is not inserted anymore.
I also tried this code:
Sub logoIneerstePagina()
With ActiveDocument
.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
With .Sections(1).Headers(wdHeaderFooterFirstPage).Shapes(1)
.Height = CentimetersToPoints(3#)
.Width = CentimetersToPoints(6)
.Left = CentimetersToPoints(10)
.Top = CentimetersToPoints(0#)
End With
End With
End Sub
In Word 2007 the logo is inserted on all pages but in Word 2003 on just one
page.
All you other questions the answer is no.
So my problem is that for 2007 the code seems to be ok but I need it also to
run in 2003. Maybe you want to take a look again?
Without seeing your documents, I do not know why it "works" in Word 2007,
but not in Word 2003.
Handling header/footers in code is a bit tricky and takes some getting used
to.
Read my first reply again, I did write:
"
Shouldn't it be more like:
.PageSetup.DifferentFirstPageHeaderFooter = False
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
"
See? I use "wdHeaderFooterPrimary", not "wdHeaderFooterFirstPage".
The result you observed seem to indicate that you have documents with a
first page header activated.
If you want to keep that first page header, then you need to insert the logo
twice, once in the first page header, and again in the primary header.
.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
If you do not need that first page header, remove it:
.PageSetup.DifferentFirstPageHeaderFooter = False
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
And, if you have documents with different odd/even headers/footers, you have
to take care of that. Maybe that what you observed is caused by this.
wdHeaderFooterPrimary is the Odd header/footer (Page one), the other page
(Page two) would be "wdHeaderFooterEvenPages".
It might well be that you need
.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
.Sections(1).Headers(wdHeaderFooterEvenPages).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
But since you are manipulating the shape, repeating the code two or three
times is not efficient, so try something like this instead:
Sub logoIneerstePagina()
InsertStuff 1 'Primary (Odd pages)
InsertStuff 2 'First Page
InsertStuff 3 'Even pages
End Sub
Function InsertStuff(lngHeaderType As Long)
Dim shpLogo As Shape
With ActiveDocument
Set shpLogo = .Sections(1).Headers(lngHeaderType).Shapes _
.AddPicture "C:\kanweg\logo copy.gif"
With shpLogo
.Height = CentimetersToPoints(3#)
.Width = CentimetersToPoints(6)
.Left = CentimetersToPoints(10)
.Top = CentimetersToPoints(0#)
End With
End With
End Function