Add Method (TablesOfContents Collection)
Applies To
TablesOfContents collection object.
Description
Adds a table of contents to a document.
Syntax
expression.Add(Range, UseHeadingStyles, UpperHeadingLevel, LowerHeadingLevel,
ú UseFields, TableID, RightAlignPageNumbers, IncludePageNumbers, AddedStyles)
expression Required. An expression that returns a TablesOfContents object.
Range Required Range. The range where you want the table of contents to appear. The table of contents replaces the range, if the range isn't collapsed.
UseHeadingStyles Optional Variant. True to use built-in heading styles to create the table of contents. If this argument is omitted, UseHeadingStyles is set to True.
UpperHeadingLevel Optional Variant. The starting heading level for the table of contents. Corresponds to the starting value used with the \o switch for a TOC (Table of Contents) field. The default value is 1.
LowerHeadingLevel Optional Variant. The ending heading level for the table of contents. Corresponds to the ending value used with the \o switch for a TOC (Table of Contents) field. The default value is 9.
UseFields Optional Variant. True if TC (Table of Contents Entry) fields are used to create the table of contents. Use the MarkEntry method to mark entries to be included in the table of contents. If this argument is omitted, UseFields is set to False.
TableID Optional Variant. A one-letter identifier that's used to build a table of contents from TC fields. Corresponds to the \f switch for a TOC (Table of Contents) field. For example, "T" builds a table of contents from TC fields using the table identifier T. If this argument is omitted, TC fields aren't used.
RightAlignPageNumbers Optional Variant. True if page numbers in the table of contents are aligned with the right margin. If this argument is omitted, RightAlignPageNumbers is set to True.
IncludePageNumbers Optional Variant. True to include page numbers in the table of contents. If this argument is omitted, IncludePageNumbers is set to True.
AddedStyles Optional Variant. The sting name for additional styles used to compile the table of contents (styles other than the Heading 1 – Heading 9 styles). Use the Add method of a HeadingStyles object to create new heading styles.
See Also
TablesOfContents collection object.
Example
This example adds a table of contents at the beginning of the active document. The table of contents is built from paragraphs styled with the Heading 1, Heading 2, and Heading 3 styles or the custom styles myStyle and yourStyle.
Set myRange = ActiveDocument.Range(0, 0)
ActiveDocument.TablesOfContents.Add _
Range:=myRange, _
UseFields:=False, _
UseHeadingStyles:=True, _
LowerHeadingLevel:=3, _
UpperHeadingLevel:=1, _
AddedStyles:="myStyle, yourStyle"