Logo in Header - Macro Question

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
 
D

Dan Kelly

OK partially solved.

The document in question has 3 Shapes that can be identified. I had assumed
that as the others were in Section(2) I would be safe, but obviously not.

I assume that the newly pasted shape is being pasted as shape 4 (or maybe 3).

Any more tips?
 
R

Russ

Dan,
Assign a meaningful name to your shape.
From Word VBA help for shapes/'Shapes Collection Object'Each shape is assigned a default name when it is created. For example, if
you add three different shapes to a document, they might be named "Rectangle
2," "TextBox 3," and "Oval 4." To give a shape a more meaningful name, set
the Name property.
 

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