Roderick
03-16-2019, 07:07 AM
This is a link from a Microsoft forum which is now closed and therefore I'm bringing it into here to continue the conversation:
https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-automatically-update-tables-of-contents/626dabcd-cdc4-4780-a979-82d1a6faefda
I have a template with two TOCs: one does Headings 1-6 whilst the other looks at Headings 7-8; each TOC working in its own purpose.
This is TOC 1:
{ TOC \o "1-6" \z }
...and this is TOC 2:
{ TOC \o "7-8" \n \p "." \z }
What I want to do is to update just the TOCs and not all the rest of the fields in the document.
The link above provides a procedure written by Doug Robbins (thanks Doug) a couple of years back:
Dim toc As TableOfContents
Dim tof As TableOfFigures
With ActiveDocument
.Range.Fields.Update
For Each toc In .TablesOfContents
toc.Update
Next toc
For Each tof In .TablesOfFigures
tof.Update
Next tof
End With
If I insert a Heading 1 title in my document and then run this procedure it updates the TOC - but once only. If I add further Headings, say 2 and 3, and run the procedure again then nothing happens.
It goes to this line and then stops without doing anything:
toc.Update
Is there something I have to adjust to make the TOCs update themselves every time?
Thanks
Roderick
https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-automatically-update-tables-of-contents/626dabcd-cdc4-4780-a979-82d1a6faefda
I have a template with two TOCs: one does Headings 1-6 whilst the other looks at Headings 7-8; each TOC working in its own purpose.
This is TOC 1:
{ TOC \o "1-6" \z }
...and this is TOC 2:
{ TOC \o "7-8" \n \p "." \z }
What I want to do is to update just the TOCs and not all the rest of the fields in the document.
The link above provides a procedure written by Doug Robbins (thanks Doug) a couple of years back:
Dim toc As TableOfContents
Dim tof As TableOfFigures
With ActiveDocument
.Range.Fields.Update
For Each toc In .TablesOfContents
toc.Update
Next toc
For Each tof In .TablesOfFigures
tof.Update
Next tof
End With
If I insert a Heading 1 title in my document and then run this procedure it updates the TOC - but once only. If I add further Headings, say 2 and 3, and run the procedure again then nothing happens.
It goes to this line and then stops without doing anything:
toc.Update
Is there something I have to adjust to make the TOCs update themselves every time?
Thanks
Roderick