InsertTableOfContents

Syntax

InsertTableOfContents [.Outline = number] [, .Fields = number] [, .From = number] [, .To = number] [, .TableId = text] [, .AddedStyles = text] [, .Replace = number] [, .RightAlignPageNumbers = number]

Remarks

Collects table-of-contents entries from headings, TC (Table of Contents Entry) fields, or both, and inserts a TOC (Table of Contents) field at the insertion point.

Argument

Explanation

.Outline

If 1, collects table-of-contents entries from heading styles.

.Fields

If 1, collects table-of-contents entries from TC (Table of Contents Entry) fields.

.From

If .Outline is 1, the highest level of heading style to collect.

.To

If .Outline is 1, the lowest level of heading style to collect.

.TableId

The entry identifier specified in those TC fields you want to include in the table of contents.

.AddedStyles

Styles to collect in addition to the heading styles indicated by .From and .To. Use the following syntax when specifying .AddedStyles:

StyleToCollect1,TOC#[,StyleToCollect2,TOC#][,¼]

You can specify any number of styles to collect, though the length of the string value cannot be longer than 256 characters. For example, .AddedStyles = "NoteStyle,3" causes text formatted with a style called "NoteStyle" to be collected into a table of contents and formatted with the TOC 3 style.

.Replace

Specifies whether to replace a previously compiled table of contents:

0 (zero) or omitted The existing table of contents is not replaced (the instruction has no effect other than to select the table).

1 The existing table of contents is replaced.

.RightAlignPageNumbers

If 1, aligns page numbers with the right margin.


Examples

This example inserts a table of contents using Heading 1 through Heading 3 styles. TC fields, if any, are excluded.


InsertTableOfContents .Outline = 1, .From = 1, .To = 3, \
        .Fields = 0, .RightAlignPageNumbers = 1, .Replace = 1

The following example inserts a table of contents using Heading 1 through Heading 3 styles and Heading 5 styles (Heading 4 styles are skipped). Note that headings formatted with the Heading 5 style are formatted with the TOC 4 style in the table of contents.


InsertTableOfContents .Outline = 1, .From = 1, .To = 3, \
    .AddedStyles = "Heading 5,4", .RightAlignPageNumbers = 1, \
    .Replace = 0

The following example inserts a table of contents based on text formatted with the "Intro," "Main heading," "Summary," and "Subhead" styles. Text formatted with the Intro, Main heading, and Summary styles is mapped to the TOC 1 style; text formatted with the Subhead style is mapped to the TOC 2 style.


custom$ = "Intro,1,Summary,1,Main heading,1,Subhead,2"
InsertTableOfContents .Outline = 0, .AddedStyles = custom$, \
        .RightAlignPageNumbers = 1, .Replace = 0

See Also

InsertTableOfAuthorities, InsertTableOfFigures, MarkTableOfContentsEntry