View Single Post
 
Old 02-08-2022, 03:03 PM
Axis Axis is offline Windows 11 Office 2019
Novice
 
Join Date: Feb 2022
Posts: 5
Axis is on a distinguished road
Default

Answer posted in case someone else runs into the issue....or I somehow forget and my own posts shows up in my google search 5 years from now. Thanks to GlowingEagle from the VBA reddit sub

Code:
Function ChangeLogo(oDoc As Document) As Boolean
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oShape As Shape
Const strImage As String = "C:\lh.png"
On Error GoTo Err_Handler
Set oSection = oDoc.Sections.First
' set first section header type - may conflict with other format desires...
oSection.PageSetup.DifferentFirstPageHeaderFooter = True
' seek first section again, otherwise logo is on wrong pages
Set oSection = oDoc.Sections.First
For Each oHeader In oSection.Headers
  If oHeader.IsHeader Then ' put logo on first header we find
    Set oShape = oHeader.Shapes.AddPicture(FileName:=strImage)
    With oShape
      .RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
      .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
      .Left = CentimetersToPoints(-1)
      .Top = CentimetersToPoints(-0.07)
     End With
     ChangeLogo = True
     Exit For  ' done, exit
  End If
Next oHeader
lbl_Exit:
  Set oSection = Nothing
  Set oHeader = Nothing
  Set oShape = Nothing
  Exit Function
Err_Handler:
  ChangeLogo = False
  Resume lbl_Exit
End Function

Last edited by Axis; 02-08-2022 at 08:27 PM.
Reply With Quote