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