Word 2003: Macro Question

PrinceNeptune

Board Regular
Joined
Jan 30, 2006
Messages
209
Hi All,

I have fields setup on my document. I have the appropriate bookmarks to be update based on an initial field that is updated.

However, when I protect the document, the only method I can find to update all the fields in the document is to manually right click it and update field.

Can someone tell me the code to update all of the fields in the document? I know how to set it up so that it runs the macro upon exit. Keep in mind you can't select all and push F9 due to the protection.

Thank you for your help.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Dim aStory As Range
Dim aField As Field

For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory

In case anyone is interested; this will update all of the fields in your document.

Enjoy!
 
Upvote 0
Hi PrinceNeptune,

Checking the 'calculate on exit' option for each of your formfields should achieve what you're after, without the need for a macro.

Also, FWIW, you macro won't update fields in the header, footer, a textbox, or all of a Table of Authorities or a Table of Contents.

Note: if you're doing calculations based on formfield contents, formula fields do this just as well as calculation formfields - and are less buggy. To see what I mean, check out my Word Field Maths 'tutorial', at:
http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=365442
or
http://www.gmayor.com/downloads.htm#Third_party
In particular, look at the item titled 'CALCULATIONS IN WORD FORMS'
 
Upvote 0
Hi Macropod,

If I use calculate on exit, are the other fields within the document going to update as well? That is my main concern.

I'm sure you are right about the headers, footers etc .. I had only achieved updating the fields themselves within the documents. Fortunately, I do not have that problem at this time.

If you can offer any easier method to updating all the fields in the remainder of the document then I'm more than happy to give it a try.

Thank you for your help.
 
Upvote 0
Hi PrinceNeptune,

What other kinds of fields do you have, and why might they not have the correct values?

Cheers
 
Upvote 0
Well, you are suggesting the "calculate on exit" option, when the fields located throughout the document will never be "entered". They will update, for the example, the name of the person and it will automatically place his name throughout the rest of the document where the bookmark is setup.

If I "calculate on exit" the Name on Page 1, will it update all the bookmarks that reference that name as well? If it does, then that is a very viable solution. If not, then I'm sort of back to square one with the macro.

Thank you for your help.
 
Upvote 0
Hi PrinceNeptune,

If you're using REF fields (eg via Insert|Cross Reference) to point to the bookmark names of the formfields, then using 'calculate on exit' will cause the cross-references to update. You don't need bookmarks at those other locations, just cross-referfences to the relevant formfields.

The same applies to calculations based on the numeric contents of formfields.

As previously mentioned, it's also better to use cross-reference & formula fields for these purposes than calculation formfields.

Cheers
 
Upvote 0
Hi Macropod,

Insert->Reference->Cross Reference was exactly what I was looking for. I was hoping there was a method without using macros ... that was it. I researched for a good hour, but was unable to come up with anything.

Thank you for your help.
 
Upvote 0

Forum statistics

Threads
1,225,385
Messages
6,184,646
Members
453,250
Latest member
unluckyuser

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top