WD: Macro to Create Table of Contents Entry Automatically

Last reviewed: February 5, 1998
Article ID: Q70996
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a

SUMMARY

The following macro examples allow you to designate selected text as a table of contents entry without removing the text from the body of the document. You do not have to type the table of contents entry twice.

MORE INFORMATION

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

You can assign the following macro to a menu, toolbar, or a key sequence to quickly designate text to be included in a table of contents:

   Sub MAIN
      a$ = Selection$()
      CharRight 1
      InsertFieldChars
      Insert "tc " + Chr$(34) + a$ + Chr$(34)
      CharRight 1
   End Sub

When you have designated all of the table of contents entries with this macro, choose Table Of Contents from the Insert menu and select Use Table Entry Fields.

Table of Contents entries or TC fields are automatically formatted as hidden text. To edit these entries, you must select either Show All or Hidden Text. In Word versions 6.x and 7.x, choose Options from the Tools menu, then choose Field Codes from the View tab. Click the Hidden Text check box to select it. In Word version 2.0 for Windows, choose Options from the Tools menu. Select the View category and mark the Hiddent Text check box. In Word version 1.0 for Windows, choose Preferences from the View menu and mark the Show All check box.

Kbcategory: kbusage kbmacro KBSubcategory: kbfield kbwordvba


Additional query words: 1.x 2.0 2.0 word6 6.0a 6.0c 7.0 word95
winword winword winword2
Keywords : kbfield kbmacroexample kbmacro
Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.