View Single Post
 
Old 08-21-2019, 01:11 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
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

Replace the field with a text content control titled "PageNum" and use the following macro to populate/update it:
Code:
Sub UpDatePageNum()
Dim oCC As ContentControl
    Set oCC = ActiveDocument.SelectContentControlsByTitle("PageNum").Item(1)
    oCC.Range.Text = oCC.Range.Information(wdActiveEndPageNumber)
    Set oCC = Nothing
End Sub
If you have more than one such field in the body of the text then replace each of them with a content control titles PageNum and use the following code to populate/update them all:
Code:
Sub UpDatePageNum()
Dim oCC As ContentControl
    For Each oCC In ActiveDocument.Range.ContentControls
        If oCC.TITLE = "PageNum" Then
            oCC.Range.Text = oCC.Range.Information(wdActiveEndPageNumber)
        End If
    Next oCC
    Set oCC = Nothing
End Sub
You may find Insert Content Control Add-In useful
__________________
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