Logo in Header of all pages

J

JN

Hi,

For printing on paper witch already has the company logo and for e-mailing I
use this macro which is triggered manualy.
It places the logo in the header of the first page but I would like the logo
to be added to the header of all pages. I use Word 2003.

Sub logoIneerstePagina()

With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True
.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(1#)
End With
End With
End Sub

Help would be very appreciated.
Thanks

Jan
 
J

Jean-Guy Marcil

JN said:
Hi,

For printing on paper witch already has the company logo and for e-mailing I
use this macro which is triggered manualy.
It places the logo in the header of the first page but I would like the logo
to be added to the header of all pages. I use Word 2003.

Sub logoIneerstePagina()

With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True
.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(1#)
End With
End With
End Sub

Help would be very appreciated.
Thanks

Might be easier said than done, depending on the document types you want
this code to run on...

First of all, your code creates the logo on the first page only on ppurpose
because of the lines:
.PageSetup.DifferentFirstPageHeaderFooter = True
.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
Why is your code making sure that the fst page is different if ythis is not
what oyu want?

Shouldn't it be more like:
.PageSetup.DifferentFirstPageHeaderFooter = False
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"

???

But the most important point is this:
Will some of the documents have more than one section already in place when
the code runs?
If not, nevermind, your code is fine.
If so, will some of these sections have their header not linked to the
previous header?
If not, nevermind, your code is fine.
If so, you will need code to address this point, this is where it gets a wee
bit more complicated...
 
F

fumei via OfficeKB.com

"If so, you will need code to address this point, this is where it gets a wee

bit more complicated..."

Chuckle. Indeed.

Jean-Guy Marcil said:
[quoted text clipped - 20 lines]
Help would be very appreciated.
Thanks

Might be easier said than done, depending on the document types you want
this code to run on...

First of all, your code creates the logo on the first page only on ppurpose
because of the lines:
.PageSetup.DifferentFirstPageHeaderFooter = True
.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
Why is your code making sure that the fst page is different if ythis is not
what oyu want?

Shouldn't it be more like:
.PageSetup.DifferentFirstPageHeaderFooter = False
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"

???

But the most important point is this:
Will some of the documents have more than one section already in place when
the code runs?
If not, nevermind, your code is fine.
If so, will some of these sections have their header not linked to the
previous header?
If not, nevermind, your code is fine.
If so, you will need code to address this point, this is where it gets a wee
bit more complicated...
 
D

Doug Robbins - Word MVP

I would start with the logo in the template by default and use code to
delete it if you do not want it.

--
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
 
J

JN

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?

Thank you.
Regards
Jan
 
D

Doug Robbins - Word MVP

Your code is just adding a picture to the FirstPage header area.

I would repeat my suggestion that you manually set up the headers in the
template and then use code to delete content from them when it is not
required.

--
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
 
J

JN

Hi Doug,

It is for a Quote template. Ther quote is always ptinted and sometimes
e-mailed after printing. That means that the user has to remove the logo
always. When I isertt a logo whith a macro the only have to do that when they
want to e-mail the PDF.
Thanks for your reply.

Regards,
Jan
 
J

Jean-Guy Marcil

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
 
J

JN

Hi Jean-Guy,

The code is now changed accarding to you first post. The logo is inserted on
all pages now.

Sub logoIneerstePagina()
With ActiveDocument
.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture
"C:\kanweg\logo copy.gif"
With .Sections(1).Headers(wdHeaderFooterPrimary).Shapes(1)
.Height = CentimetersToPoints(3#)
.Width = CentimetersToPoints(6)
.Left = CentimetersToPoints(10)
.Top = CentimetersToPoints(1#)
End With
End With
End Sub

Thank you very much for your help.

Regards
Jan
 

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