Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2023, 11:52 PM
gmayor's Avatar
gmayor gmayor is offline Adding footer page number with custom style Windows 10 Adding footer page number with custom style Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
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 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
  #2  
Old 12-21-2023, 11:22 PM
laith93 laith93 is offline Adding footer page number with custom style Windows 10 Adding footer page number with custom style Office 2019
Competent Performer
Adding footer page number with custom style
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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.
Thanks so much dear Graham
It works perfectly
Best Regards
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding footer page number with custom style Updating page number in table cells in footer in each page nyconfidential Word VBA 1 08-13-2022 03:37 PM
Adding footer page number with custom style Page number shows up as { PAGE } instead of number and question about area allowed for footer dw85745 Word 3 01-16-2022 03:19 PM
Don't want page number or date in footer on first page, do want graphic in header. dianahbr Word 2 02-23-2018 09:25 AM
Adding footer page number with custom style Footer for page numbers recently started showing a colored field when adding page numbers thefonebug Word 12 10-24-2016 05:18 AM
Adding footer page number with custom style Total Page number incorrect in the first page footer mmathisekar Word 11 06-16-2016 06:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft