View Single Post
 
Old 12-13-2023, 01:48 PM
laith93 laith93 is offline Windows 10 Office 2019
Competent Performer
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default Adding footer page number with custom style

Hi,
I want a macro to add a footer with the page number on the right, the distance from the bottom (1cm), the style of footer text (Times new roman, 14pt), I tried and used this macro, but didn't fulfill my requirement

Code:
Sub AddFooterWithPageNumber()
    Dim section As section
    Dim footer As range
    
    ' Loop through each section in the document
    For Each section In ActiveDocument.Sections
        Set footer = section.Footers(wdHeaderFooterPrimary).range
        
        ' Clear existing content in the footer
        footer.Text = ""
        
        ' Set font properties
        With footer.Font
            .Name = "Times New Roman"
            .Size = 14
        End With


        Dim positionFromBottom As Double
        positionFromBottom = CentimetersToPoints(1)
        
        footer.Fields.Add range:=footer, Type:=wdFieldPage
        
        ' footer.Text = " - "  ' Uncomment this line if you want to add a separator
       
        
'         Update the footer
'        footer.Updates
    Next section
End Sub
Any help, suggestions
Thanks
Reply With Quote