Insert Logo in Section Header

J

James Pannozzi

I have a document with Section Headers
which consist of a logo and some text below it.
The logo remains the same but the text differs from
section to section.

I've been going crazy trying to figure out a way to use VBA to
just insert the bmp logo in one spot and have it appear
in all the section headers.

Next I tried just Adding it to the Section Headers one at a time
but still nothing appears.

The differing text I can insert into the Section headers with no problem
(it is currently just putting some test text in Sections 1,2 and 3).
its the damn logo ...

Here is the code I am using.

Thanks
J

Dim oRng
For i = 1 To objWord.ActiveDocument.Sections.count
With objWord.ActiveDocument.Sections(i)
.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
If i = 1 Then
' Add the Logo to the header and insert the header text in
the header
'tried various ways of getting cglogo.bmp into header -
InLineShapes?? or AddPicture?
.Headers(wdHeaderFooterFirstPage).Range.Collapse
wdCollapseEnd
' Set MyInlineShape =
..Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture
"H:\CGLogo.bmp",False,True,.Headers(wdHeaderFooterFirstPage).Range

Set oRng =
objWord.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
objWord.ActiveDocument.Fields.Add
oRng,wdFieldIncludePicture,"h:\CGLogo.bmp",True

.Headers(wdHeaderFooterFirstPage).Range.Collapse
wdCollapseEnd

'THE REST OF THE CODE WORKS FINE
.Headers(wdHeaderFooterFirstPage).Range.InsertFile
"H:\header1.txt" 'use C:\header.txt For testing
' Set MyRange =
objWord.Selection.Sections(i).Headers(wdHeaderFooterPrimary).Range
.Headers(wdHeaderFooterFirstPage).Range.Font.Bold = True
.Headers(wdHeaderFooterFirstPage).Range.Font.Size = 12
.Headers(wdHeaderFooterFirstPage).Range.Font.Name = "Times
New Roman"

End If

If i = 2 Then
.Headers(wdHeaderFooterFirstPage).Range.Text = "Some 222
Other Text"
End If

If i = 3 Then
.Headers(wdHeaderFooterFirstPage).Range.Text = "Some 3333 333
Other Text"
End If

End With
Next
 
J

James Pannozzi

Got it.
This does it,

.Headers(wdHeaderFooterPrimary).Shapes.AddPicture "H:\SomeLogo.bmp"

Apparently you have to do it twice when you have sections,
once for wdHeaderFooterFirstPage and once for wdHeaderPrimary.

I know you can do it from a template on a document with no sections,
but am not sure about putting the same logo in all the section headers
(first page and on any other pages in the section)
from a template when you have a document with sections.

J
 

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