VBA macro in Word global template

V

v_fas

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
 
D

Doug Robbins - Word MVP

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
 
V

v_fas

Hi,

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

Code NOw:
 
V

v_fas

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
 
V

v_fas

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
 
D

Doug Robbins - Word MVP

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
 

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