Word VBA -How do I insert a formula into a header while still using range? I don't know how to start/end the formula field. I'm trying to insert:
Page { =(intPgNo + {PAGE \* MERGEFORMAT })}
The following works by switching to selection, but I have been unable to produce either the wdFieldEmpty or Control F9 combination. r is the range within the header.
Thank you in advance
pjk
Page { =(intPgNo + {PAGE \* MERGEFORMAT })}
The following works by switching to selection, but I have been unable to produce either the wdFieldEmpty or Control F9 combination. r is the range within the header.
Code:
r.Collapse Direction:=wdCollapseEnd
r.InsertAfter Text:=frmMain.txtDate _
& vbTab & vbTab & "Page "
'------------------------
'Insert Page Number field
'------------------------
r.Collapse Direction:=wdCollapseEnd
'*******************************************
r.Select
W.Selection.Fields.Add Range:=W.Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
W.Selection.TypeText Text:="=("
W.Selection.TypeText Text:=intPgNo & " + "
W.Selection.Fields.Add Range:=W.Selection.Range, Type:=wdFieldPage
W.Selection.TypeText Text:=")"
W.Selection.MoveRight Unit:=wdCharacter, count:=2
W.Selection.TypeText Text:=vbCr & vbTab
W.Selection.TypeText Text:="File: " & UCase$(FileName$) & " "
W.Selection.TypeText Text:="Page "
W.Selection.Fields.Add Range:=W.Selection.Range, Type:=wdFieldPage
W.Selection.TypeText Text:=" of pjk"
'*******************************************
Thank you in advance
pjk