I have a Word document that uses many different fields. I wrote a macro that updates all the sequence
, reference
, page, and numpages
fields in the document.
Updating text fields reverts them back to their default text so I don't want those updated.
This macro worked perfectly in Word 2007 but I recently updated to Word 2013 and it doesn't work properly anymore.
All page and numpages
fields are set to 1 when this macro runs. Yet when I update them manually, they update correctly.
Was there a change to how fields are updated in Office 2013?
The macro code is below.
Sub UpdateAllFields()
UnprotectDocument
'UpdateAllFields Macro
Dim objDoc As Document
Dim objFld As Field
'Updates the specified form fields. This can take a while when the document gets large
Set objDoc = ActiveDocument
For Each objFld In objDoc.Fields
If objFld.Type = wdFieldRef Then 'Updates Cross References
objFld.Update
If objFld.Type = wdFieldPage Then 'Updates Page Numbers
objFld.Update
ElseIf objFld.Type = wdFieldNumPages Then 'Updates Total Page Count
objFld.Update
ElseIf objFld.Type = wdFieldSequence Then 'Updates Sequence Fields
objFld.Update
End If
Next objFld
ProtectDocument
End Sub
UnprotectDocument
sub Function? – 0m3rIF THEN ELSE Statement
is incomplete – 0m3rFields(...).Update
setsPAGEREF
s to1
instead of the correct page number. His installation behaves differently than mine does, so it may be something in the Registry, which updates are installed, or any of the usual per-machine suspects. – cxw