VBA to update TOC

S

Steve Hodgson

I've written a very simple VB Word macro to update the tables of
contents in a Word file but would like to extend this to include a
table of tables.

The document includes a Table each of Contents, Figures and Tables
that I want to be able to updated without the need to hit <ctrl>-A, F9
and then make the selection to update all table contents three times.

The macro below works for contents and figures but not for tables. Is
there a straightforward way to extend it to cover a table of tables
which is defined by { TOC /T "TAB_TITLE" \C }.

Sub Update_TOC()
'
' Update_TOC Macro
' Macro created 20/01/2010
'
ActiveDocument.TablesOfContents(1).Update
ActiveDocument.TablesOfFigures(1).Update
End Sub
 
M

macropod

Hi Steve,

Try something along the lines of:
Sub UpdateRefTables()
Dim TOC As TableOfContents ' Table of Contents Object
Dim TOA As TableOfAuthorities ' Table of Authorities Object
Dim TOF As TableOfFigures ' Table of Figures Object
With ActiveDocument
' The following routines update TOC, TOA or TOF contents.
' Loop through Tables Of Contents and update
For Each TOC In .TablesOfContents
TOC.Update
Next
' Loop through Tables Of Authorities and update
For Each TOA In .TablesOfAuthorities
TOA.Update
Next
' Loop through Tables Of Figures and update
For Each TOF In .TablesOfFigures
TOF.Update
Next
End With
End Sub
 
F

frank minor

Hi macropad,

I have utilized this VB script to attempt expanding the TOC in an automated batch fashion, but I am seeing something very strange appear, and that is a pop up box which states the following:

Word is updating the table of contents. Select one of the following options:

Update page numbers only
Update entire table.

I assumed using the TOC.update that the default would be the entire table would be updated. How can we get passed this and have the macro automatically make the TOC update properly. Please advise. Thanks in advance - frank
 

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