Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2012, 09:28 PM
macropod's Avatar
macropod macropod is offline Update TOC Windows 7 64bit Update TOC Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Actually, I'd have thought it would be more useful to ensure the TOC updates upon opening, as that ensures the refernces match any repagination, etc due to printer changes and the like. Adding the following macro to the Normal Template's 'ThisDocument' module will update all fields in every document that gets opened:
Code:
Private Sub Document_Open()
Application.ScreenUpdating = False
Dim TOC As TableOfContents    ' Table of Contents Object
Dim TOA As TableOfAuthorities ' Table of Authorities Object
Dim TOF As TableOfFigures     ' Table of Figures Object
Dim Rng As Range              ' Word Range Object
With ActiveDocument
  ' Update fields in each Story.
  ' Note that this may trigger the updating of ASK & FILLIN fields
  For Each Rng In .StoryRanges
    .Fields.Update
  Next
  ' The following routines are necessary because the foregoing updates only page numbers
  ' in TOCs, TOAs and TOFs - field updating doesn't 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
Application.ScreenUpdating = True
End Sub
Note: Venky's code will throw an error if the document doesn't have a Table Of Contents.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Update TOC Organizer does not update some styles Jennifer Murphy Word 10 08-31-2015 08:54 AM
live update gilgold Excel 0 05-26-2010 10:49 AM
VBA to update certain (but not all) fields sparkyrose Word VBA 0 05-20-2010 12:50 PM
Project Auto-Update hB-sys Project 0 04-15-2010 06:46 AM
MS update failure kbstinky Outlook 0 07-18-2009 10:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft