I have requirement to maintain a standard footer in Word documents. The footer contains doc id and version, which can change, so I must be able not only insert this standard footer, but also update it.
I need to identify just the standard string part of the footer and update it. The string looks like <<Libray:DocId:vX>>
(the angle brackets are to help match the beginning and end of the standard footer).
A concern is that the brackets alone aren't enough to reliably identify the standard string, so I am doing a RegEx ("<<[A-Za-z0-9_-]+:\d+v\d+>>")
match and Replace to achieve the update, but it seems modifying the Text property wipes out any formatting and active content.
If I can't use RegEx.Replace on the Text property w/o losing formatting, is there another way to tag and update just the standard string?
If oRegEx.Test(strFooter) Then
' Set the footer for the active document
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
.Style = wdStyleFooter
.Font.Size = 8
.Text = oRegEx.Replace(strFooter, strTextString) 'this wipes out page numbering and formatting
End With
Else
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
.Style = wdStyleFooter
.Font.Size = 8
.InsertAfter strJoiner & strTextString 'this preserves formatting and active content
End With
End If
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter " yadda!!"
. – LocEngineer