I’m trying to replace an image in a MS Word header using this:
For Each tmp In ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes
If tmp.Type = msoPicture Then
Set dShape = tmp
End If
Next
Dim w, h, t, l As Single
Dim lic As Long
Dim rhp As WdRelativeHorizontalPosition
Dim rvp As WdRelativeVerticalPosition
dShape.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
dShape.RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
With dShape
w = .Width
h = .Height
t = .Top
l = .Left
lic = .LayoutInCell
End With
Dim shp As Shape
Set shp = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.AddPicture("C:\aa.jpg", False, True, l, t, w, h)
shp.RelativeVerticalPosition = rvp
shp.RelativeHorizontalPosition = rhp
shp.LayoutInCell = lic
dShape.Select
dShape.Delete
But new image is not placed on the previous image position!
What is the problem?
How can I place new image on exactly on the previous image position?
Thanks
Some steps to follow:
Your old image is still in the position when you are trying to add the new one…so remove the old…;)
inline with text,square..etc) of old image before deletingtop, left, width, heightand other properites matching the old image’s valuesCode changes: