Update an entire document

M

Mark64

I have the following macro that I was given from another question here, which
I use to update an entire document, fields, headers, footers, everything.
However I have noticed that it is not updating my Table of Contents and Table
of Figures. Do I need to add something more to this.

Dim pRange As Word.Range
For Each pRange In ActiveDocument.StoryRanges
Do Until pRange Is Nothing
pRange.Fields.Update
Set pRange = pRange.NextStoryRange
Loop
Next
 
T

Tony Jollans

Yes, Fields.Update does not update TOC fields. try adding something like
this

Dim TOC As TableOfContents
For Each TOC In ActiveDocument.TablesOfContents
TOC.Update
Next

For a more complete solution you might like to try:

Dim TOC As TableOfContents
Dim TOF As TableOfFigures
Dim TOA As TableOfAuthorities

For Each TOC In ActiveDocument.TablesOfContents
TOC.Update
Next
For Each TOF In ActiveDocument.TablesOfFigures
TOF.Update
Next
For Each TOA In ActiveDocument.TablesOfAuthorities
TOA.Update
Next
 
J

Jay Freedman

I have the following macro that I was given from another question here, which
I use to update an entire document, fields, headers, footers, everything.
However I have noticed that it is not updating my Table of Contents and Table
of Figures. Do I need to add something more to this.

Dim pRange As Word.Range
For Each pRange In ActiveDocument.StoryRanges
Do Until pRange Is Nothing
pRange.Fields.Update
Set pRange = pRange.NextStoryRange
Loop
Next

Yes, add one of these loops after the Next, depending on whether you
want to update the entries or just the page numbers of the existing
entries:

Dim oTOC As TableOfContents
For Each oTOC In ActiveDocument.TablesOfContents
oTOC.Update
Next oTOC

Dim oTOC As TableOfContents
For Each oTOC In ActiveDocument.TablesOfContents
oTOC.UpdatePageNumbers
Next oTOC

and a similar one for the Table of Figures.
 
M

Mark64

Awesome! Thanks Tony!

Tony Jollans said:
Yes, Fields.Update does not update TOC fields. try adding something like
this

Dim TOC As TableOfContents
For Each TOC In ActiveDocument.TablesOfContents
TOC.Update
Next

For a more complete solution you might like to try:

Dim TOC As TableOfContents
Dim TOF As TableOfFigures
Dim TOA As TableOfAuthorities

For Each TOC In ActiveDocument.TablesOfContents
TOC.Update
Next
For Each TOF In ActiveDocument.TablesOfFigures
TOF.Update
Next
For Each TOA In ActiveDocument.TablesOfAuthorities
TOA.Update
Next
 

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