Windows 7 - VBA macro in Word global template

Asked By vfa on 18-Jun-08 08:08 PM
I ahve a Word 2003 main.dot global template.  I need to bea able to insert a
logo inside the header on the firs tpage; but to leave alone and not consider
a focus the second page header.  below is the code.

************
Public Function InsertLogo(strLogoPath As String) As Boolean

On Error GoTo ErrHandler

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
With ActiveDocument 'msadded
.PageSetup.DifferentFirstPageHeaderFooter = True 'msadded
With .Sections(1).Headers(wdHeaderFooterFirstPage) 'msadded
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.InlineShapes.AddPicture FileName:=strLogoPath,
LinkToFile:=False, _
SaveWithDocument:=True

InsertLogo = True
Exit Function
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End With 'msadded

End With

'############################
ErrHandler:
'############################

InsertLogo = False

FunctionName = "Main.InsertLogo"
strmsg = ""

Call Main.ErrorHandler(FunctionName, strmsg)

End Function




Doug Robbins - Word MVP replied on 19-Jun-08 07:16 AM
Use

Dim myrange As Range

Set myrange = Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
myrange.InlineShapes.AddPicture filename:=strLogoPath, _
LinkToFile:=False, SaveWithDocument:=True, Range:=myrange


--
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
vfa replied on 19-Jun-08 08:44 AM
Hi,

It stops the erro, but it also does not allow the insertion of the header.

Code NOw:
vfa replied on 19-Jun-08 09:43 AM
Actually, it placed the logo into the second page header.  It should be
inserted into the first page header.

*******************
Public Function InsertLogo(strLogoPath As String) As Boolean

On Error GoTo ErrHandler

With ActiveDocument 'msadded
.PageSetup.DifferentFirstPageHeaderFooter = True 'msadded
Dim myrange As Range
Set myrange = Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
myrange.InlineShapes.AddPicture FileName:=strLogoPath, _
LinkToFile:=False, SaveWithDocument:=True, Range:=myrange
InsertLogo = True
Exit Function
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End With 'msadded

Exit Function

'############################
ErrHandler:
'############################

InsertLogo = False

FunctionName = "Main.InsertLogo"
strmsg = ""

Call Main.ErrorHandler(FunctionName, strmsg)

End Function
*****************8
vfa replied on 19-Jun-08 11:50 AM
This ended up working for me with a bit of change:

Public Function InsertLogo(strLogoPath As String) As Boolean
On Error GoTo ErrHandler

Dim myrange As Range

With ActiveDocument
.PageSetup.DifferentFirstPageHeaderFooter = True

Set myrange = Selection.Sections(1).Headers(wdHeaderFooterFirstPage).Range
myrange.InlineShapes.AddPicture FileName:=strLogoPath, _
LinkToFile:=False, SaveWithDocument:=True, Range:=myrange

InsertLogo = True

Exit Function

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

End With

Exit Function

'############################

ErrHandler:

'############################

InsertLogo = False

FunctionName = "Main.InsertLogo"

strmsg = ""

Call Main.ErrorHandler(FunctionName, strmsg)

End Function
Doug Robbins - Word MVP replied on 19-Jun-08 03:32 PM
Sorry, the code should have been:

Dim myrange As Range

Set myrange = Selection.Sections(1).Headers(wdHeaderFooterFirstPage).Range
myrange.InlineShapes.AddPicture filename:=strLogoPath, _
LinkToFile:=False, SaveWithDocument:=True, Range:=myrange



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