Results 1 to 8 of 8
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Updating TOCs (VBA/Word/2000 SP-3)

    <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15> I am trying to update my Table of Contents. When recording the action, I am presented with an option of updating the complete table or just the page numbers. Irrespective of which selection I make, the recorded code:
    <pre>Selection.Fields.Update</pre>

    does not update the entire table; just the page numbers.

    Is anyone aware of modified code that will force upgrading of the complete table?

    TIA
    Regards
    Don

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    As I recall, the only way, silly as it may seem, is to actuallly copy and paste the field codes and then update the field.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    Instead of the Fields collection of a Range (Selection), you can use the TablesOfContents collection of the Document:

    ActiveDocument.TablesOfContents(1).Update

    will update the entire TOC, while

    ActiveDocument.TablesOfContents(1).UpdatePageNumbe rs

    will only update the page numbers.

  4. #4
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    Thanks Hans
    The same philosophy works beautifully with Tables of Figures as well. I was just plain using the wrong collection.
    Thanks again for the guidance.
    Regards
    Don

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    Howard
    Thanks for your input. I was unable to get your approach to work. You might be interested in Hans' response; it did the trick for me. Thanks again for your time.
    Regards
    Don

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    i last used the field replacement trick many years ago, but it should still work if one deletes the old field, inserts a new field with the sabe field options and then updates the field, same as if the field had been inserted anew.

  7. #7
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    Howard,

    That approach is dangerous!

    When you generate a TOC, Word creates a set of hidden bookmarks for the TOC entries. If you delete a TOC (with or without vba), these bookmarks are left behind. If you then create a new TOC (with or without vba), Word generates a new set of bookmarks instead of just re-using the existing ones. Eventually, the accumulation of unused
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating TOCs (VBA/Word/2000 SP-3)

    by itself, i've never seen accumulating unused bookmarks causing corruption of a document.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •