We have a VBA macro that let the users add headers to word documents from a list from files. It pretty much only adds the file as a shape. See code below. This worked for at least 15 years, but since last december it broke. The 'border' for the inserted shape was directly top- left of the first letter or picture in the file. See screenshot. (All headers are stored as .doc files)
But now the 'border' is correct for some files, but for other it's far more to the top and left. See screenshot.
We did not change anything in the code and also did not change the files. I'm not sure if the could be related to a word update. Did anything change in Word that the AddOLEObject uses different selections of the file handed over?
Can somebody help?
Set oShape = ActiveDocument.Shapes.AddOLEObject(fileName:=header...
Private Sub addHeader()
header = "pathtoheaderfile"
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=1
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Set oShape = ActiveDocument.Shapes.AddOLEObject(fileName:=header _
, LinkToFile:=False _
, DisplayAsIcon:=False _
, Anchor:=Selection.Range)
With oShape
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Left = CentimetersToPoints(2)
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Top = CentimetersToPoints(1)
.LockAnchor = True
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapBoth
.WrapFormat.DistanceTop = CentimetersToPoints(0)
.WrapFormat.DistanceBottom = CentimetersToPoints(0)
.WrapFormat.DistanceLeft = CentimetersToPoints(0)
.WrapFormat.DistanceRight = CentimetersToPoints(0)
.WrapFormat.Type = 5
End With
End Sub