reference - Updating page numbers in VBA -
i have word document uses many different fields. wrote macro updates sequence
, reference
, page, , numpages
fields in document.
updating text fields reverts them default text don't want updated.
this macro worked in word 2007 updated word 2013 , doesn't work anymore.
all page , numpages
fields set 1 when macro runs. yet when update them manually, update correctly.
was there change how fields updated in office 2013?
the macro code below.
sub updateallfields() unprotectdocument 'updateallfields macro dim objdoc document dim objfld field 'updates specified form fields. can take while when document gets large set objdoc = activedocument each objfld in objdoc.fields if objfld.type = wdfieldref 'updates cross references objfld.update if objfld.type = wdfieldpage 'updates page numbers objfld.update elseif objfld.type = wdfieldnumpages 'updates total page count objfld.update elseif objfld.type = wdfieldsequence 'updates sequence fields objfld.update end if next objfld protectdocument end sub
it happened me page references pointed page 1 in document when used activedocument.fields.update, worked when updated them manually. after trial , error noticed worked using selection.fields.update, modified macro following:
sub updateallfields() dim ocurrentrng range dim orng range application.screenupdating = false set ocurrentrng = selection.range set orng = activedocument.range orng.select selection.fields.update ocurrentrng.select application.screenupdating = true end sub
hope helps someone!
//david
Comments
Post a Comment