View Single Post
 
Old 02-08-2022, 02:15 PM
Axis Axis is offline Windows 11 Office 2019
Novice
 
Join Date: Feb 2022
Posts: 5
Axis is on a distinguished road
Default VBA Insert Image(logo) into header for multiple Word Docs

I've modified an old macro from gmayor that I've found. However, while I know how to choose only the first page header in a sub, I'm not sure how to do it in a function.


Code:
Option Explicit

Function ChangeLogo(oDoc As Document) As Boolean
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oShape As Shape
'change the path as appropriate
Const strImage As String = "C:\lh.png"
On Error GoTo err_handler
        For Each oSection In oDoc.Sections
        For Each oHeader In oSection.Headers
            Set oShape = oHeader.Shapes.AddPicture(FileName:=strImage)
                    With oShape
                        .RelativeHorizontalPosition = _
                        wdRelativeHorizontalPositionColumn
                        .RelativeVerticalPosition = _
                        wdRelativeVerticalPositionParagraph
                        .Left = CentimetersToPoints(-1)
                        .Top = CentimetersToPoints(-0.07)
                    End With
                    ChangeLogo = True
        Next oHeader
    Next oSection
lbl_Exit:
    Set oSection = Nothing
    Set oHeader = Nothing
    Set oShape = Nothing
    Exit Function
err_handler:
    ChangeLogo = False
    Resume lbl_Exit
End Function
My plan was to use Document Batch Processes to batch the process to run for all the word docs. However, the problem is I do not know how to set it for only the first page. Any help would be apprerciated!

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