D
Dan Kelly
All our documents have the company logo on them on Page 1 of the document.
As this logo can be one of a number of colours I have the attached Macro that
makes the appropriate change.
In my latest document when the macro is first run, the new logo does not
change its position as per the end of the macro. The second time the macro
is run the position changes, but not the colour.
Any suggestions?
Private Sub ChangeLogo()
'Declare our variables
Dim LogoName As String
Dim x As Single, y As Single, h As Single, w As Single
Dim oHeader As Word.HeaderFooter
Dim rngA As Word.Range
x = 0
y = 0
'Select Page 1 Header
Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage)
With oHeader
'We Assume that there is only one shape in the header
With .Shapes(1)
x = .Left
y = .Top
h = .Height
w = .Width
Set rngA = .Anchor
End With
'Delete the Existing Image in the Header
.Shapes(1).Delete
' Set the file to be inserted
LogoName = SetLogoName
.Shapes.AddPicture FileName:=LogoName, LinkToFile:=False,
SaveWithDocument:=True, _
Left:=x, Top:=y, Width:=w, Height:=h, Anchor:=rngA
'Reposition the logo?
.Shapes(1).RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
.Shapes(1).RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Shapes(1).Left = x
.Shapes(1).Top = y
End With
End Sub
As this logo can be one of a number of colours I have the attached Macro that
makes the appropriate change.
In my latest document when the macro is first run, the new logo does not
change its position as per the end of the macro. The second time the macro
is run the position changes, but not the colour.
Any suggestions?
Private Sub ChangeLogo()
'Declare our variables
Dim LogoName As String
Dim x As Single, y As Single, h As Single, w As Single
Dim oHeader As Word.HeaderFooter
Dim rngA As Word.Range
x = 0
y = 0
'Select Page 1 Header
Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage)
With oHeader
'We Assume that there is only one shape in the header
With .Shapes(1)
x = .Left
y = .Top
h = .Height
w = .Width
Set rngA = .Anchor
End With
'Delete the Existing Image in the Header
.Shapes(1).Delete
' Set the file to be inserted
LogoName = SetLogoName
.Shapes.AddPicture FileName:=LogoName, LinkToFile:=False,
SaveWithDocument:=True, _
Left:=x, Top:=y, Width:=w, Height:=h, Anchor:=rngA
'Reposition the logo?
.Shapes(1).RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
.Shapes(1).RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Shapes(1).Left = x
.Shapes(1).Top = y
End With
End Sub