WD: TOC Field Not Updated Properly from MacroLast reviewed: February 23, 1998Article ID: Q122555 |
The information in this article applies to:
SYMPTOMSIf you use a macro to update a TOC (table of contents) field, Microsoft Word may not prompt you to choose either Update Page Numbers Only or to Update Entire Table. Word only updates the page numbers.
CAUSEWord defaults to Update Page Numbers Only.
WORKAROUNDMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/supportnet/refguide/default.aspYou can use a macro to replace the existing table of contents, and in effect, duplicate the Update Entire Table option programmatically. The following sample macro locates the TOC field and uses the InsertTableOfContents command to replace the existing table of contents and retains all formatting previously applied to the original table.
Sub MAIN StartOfDocument 'Move insertion point to start of document. OldVFC = ViewFieldCodes() 'Get the current state of ViewFieldCodes. ViewFieldCodes 1 'Turn on Field Codes. EditFindClearFormatting 'Clear EditFind formatting setting. EditFind .Find = "^19 toc" 'Find the first TOC field. InsertTableOfContents .Replace = 1 'Replace current table. ViewFieldCodes OldVFC 'Restore ViewFieldCodes setting. End SubNOTE: If you have converted your WordBasic macros to Visual Basic for Applications, the following routines demonstrate how to update a Table of Contents using Visual Basic for Applications:
Sub UpdateTOC() ' Update the entire first Table of Contents ' in the active document. ActiveDocument.TablesOfContents(1).Update End SubTo update only the page numbers of a Table of Contents:
Sub UpdateTOC() ' Update only the page numbers of the first ' Table of Contents in the active document. ActiveDocument.TablesOfContents(1).UpdatePageNumbers End SubFor additional information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q163435 TITLE : VBA: Programming Resources for Visual Basic for Applications REFERENCES"Microsoft Word User's Guide," version 6.0. Document number WB51157-1093, pages 457-458 and 738.
|
Additional query words: macro toc table page numbers entire
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |