IVO JGMs post then maybe:
Sub InsertNestedPageFieldInFooterOnTheFly()
Dim MyRange As Range
Dim myString As String
'Strip extention from file name and path
myString = ActiveDocument.FullName
myString = Left(myString, Len(myString) - 4)
Application.ScreenUpdating = False
ActiveWindow.View.ShowFieldCodes = True
'Insert dummy para at end of document
ActiveDocument.Range.InsertAfter vbCr
Set MyRange = ActiveDocument.Range
MyRange.Collapse wdCollapseEnd
MyRange.Select
'Insert nested field
With Selection
.Font.Size = 8
.Font.Color = wdColorGray90
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="IF"
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdMove
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="PAGE"
.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdMove
.TypeText Text:=" = "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
.TypeText Text:="NUMPAGES"
.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdMove
.TypeText Text:=Chr(34) & myString & Chr(34)
'.Fields.Update
End With
ActiveWindow.View.ShowFieldCodes = False
'Cut field, delete dummy para mark, and paste field into header
With Selection
.MoveEndUntil Cset:=Chr(34), Count:=wdForward
.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
.Cut
End With
'ActiveDocument.Paragraphs.Last.Range.Delete
Set MyRange = ActiveDocument.Sections(1) _
.Footers(wdHeaderFooterPrimary).Range
MyRange.Collapse wdCollapseEnd
MyRange.Paste
Set MyRange = ActiveDocument.Sections(1) _
.Footers(wdHeaderFooterPrimary).Range
MyRange.Paragraphs.Last.Range.Delete
Application.ScreenUpdating = True
End Sub