WD: Macro to Create Table of Contents Entry Automatically

ID: Q70996

The information in this article applies to:

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          : kbmacro kbmacroexample kbfield 
Version           : 2.x 6.0 6.0a 6.0c 7.0 7.0a
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: February 6, 1998