Automatically Updating Cross-reference to Caption

B

BLB

I have inserted captions manually to my Figures and also
cross-references. Whenever I insert a new figure, I update the field,
to update the numbering, but the cross-reference associated with that
figure does not automatically update. I have to then select the
cross-reference and update that field as well. This is very
cumbersome. I know I can select the whole document and hit F9 to update
everything, but is there a way that the cross-references will
automatically update to the new caption number when I "update field" on
the caption?

Thanks for your Help.
 
S

Stefan Blom

There is a built-in semi-automatic way, namely to have Word update
fields on print. On the Tools menu, click Options. Click the Print
tab. Make sure the "Update fields" option is checked, and click OK.

Alternatively, after you've inserted a cross-reference, you can run
the (simple) macro below:

Sub UpdateMyFields()
Dim t As TableOfContents
Dim f As Field

For Each t In ActiveDocument.TablesOfContents
t.Update
Next t

For Each f In ActiveDocument.Fields
f.Update
Next f

End Sub

You can attach the macro to a keyboard shortcut for ease of use.

If you need assistance, please see:

What do I do with macros sent to me by other newsgroup readers to help
me out?
http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

How to assign a Word command or macro to a hot-key
http://word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToHotkey.htm

The macro represents a slight improvement on using "Update fields"
from the context menu (or using the built-in F9 keyboard shortcut) in
the following sense: You don't need to select the text first; the
macro automatically updates all fields in the body of the active
document. In addition, it will perform a complete update on any table
of contents field, without asking. In other words, there will be no
need to choose between a full update and an update of page numbers
only.

If you want to make sure that fields contained in headers and footers
are also updated, replace the lines including the variable "f" (that
is, the "Dim f As Field, For Each f In ... Next f" lines) with the
code supplied by Graham Mayor in his article at
http://www.gmayor.com/installing_macro.htm.

Technical Discussion: Since table of contents are also fields, why do
they need to be addressed separately in the code? The explanation is
that even though the Fields collection of a document includes any
table of contents (or table of figures) in the main body of the
document, updating a TOC when referenced as a Field object updates the
*page number* only. For that reason, I included an update of
TableOfContents objects as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top