Macro to refresh document properties

G

Guest

I'm having trouble creating a macro that will refresh all the document
properties in my document, including data contained in the fields in File >
Properties, headers and footers, and table of contents.

The usual method I use to update all properties in the document is to go to
Normal view, then Ctrl+A to select everything in the document, then hit the
F9 key (and if the document contains a TOC I'm prompted to update the table,
to which I select "Update entire table" then OK). This then updates all
fields in the document.

What I'm trying to do is insert a button onto my toolbar that is linked to a
macro, but each time I create the macro following the steps described above,
the macro updates all the document properties except for the TOC.

I then tried to create a macro that only refreshes the TOC, but once I'm in
record macro mode, I can't actually select the TOC so that I can right-click
it. I've even tried to do Edit, Go To, Field, TOC (there's only 1 TOC in my
document), but when I run the macro nothing happens and it seems to not
refresh my TOC.

I don't want to overwrite the TOC, just refresh it, and there doesn't seem
to be a button anywhere in the File menu to do this. I'm also not familiar
with the coding syntax in Visual Basic Editor to change this.

Any suggestions would be much appreciated.

Thank you.
 
G

Guest

If you have created your current macro by recording, you may want to replace
it by more efficient code. For example, use the UpdateAll macro here to
update all fields in the document:
http://www.gmayor.com/installing_macro.htm

About updating the TOC:
The following line of code will update the first table of contents in the
active document (corresponding to "Update entire table"):

ActiveDocument.TablesOfContents(1).Update

To update only the page numbers:

ActiveDocument.TablesOfContents(1).UpdatePageNumbers

To prevent an error if the document contains no table of contents, you could
do as follows:

With ActiveDocument
If .TablesOfContents.Count > 0 Then
.TablesOfContents(1).Update
End If
End With

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

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