View Single Post
 
Old 12-18-2023, 11:52 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

OK. The default footer has tabs at the centre and right so the simplest approach is to use that and add two tabs and the text to the end of the range e.g.


Code:
Sub AddFooterWithPageNumber()
    Dim oSection As section
    Dim oFooter As HeaderFooter
    Dim oRng As Range
    
    ' Loop through each section in the document
    For Each oSection In ActiveDocument.Sections
        oSection.PageSetup.FooterDistance = CentimetersToPoints(1)
        For Each oFooter In oSection.Footers
            If oFooter.Exists Then
                Set oRng = oFooter.Range
                ' Set font properties
                With oRng.Font
                    .Name = "Times New Roman"
                    .Size = 14
                End With
                oRng.Fields.Add oRng, wdFieldPage, , False
                oRng.Collapse wdCollapseEnd
                oRng.Text = Chr(9) & Chr(9) & "laith"
            End If
        Next oFooter
    Next oSection
lbl_Exit:
    Set oSection = Nothing
    Set oFooter = Nothing
    Set oRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote