DocumentBase.TablesOfContents Property

Definition

Gets a TablesOfContents collection that represents the tables of contents in the document.

public:
 property Microsoft::Office::Interop::Word::TablesOfContents ^ TablesOfContents { Microsoft::Office::Interop::Word::TablesOfContents ^ get(); };
public Microsoft.Office.Interop.Word.TablesOfContents TablesOfContents { get; }
member this.TablesOfContents : Microsoft.Office.Interop.Word.TablesOfContents
Public ReadOnly Property TablesOfContents As TablesOfContents

Property Value

A TablesOfContents collection that represents the tables of contents in the document.

Examples

The following code example adds two paragraphs to the document and assigns the Heading 1 and Heading 2 styles to the paragraphs. The code then creates a table of contents at the insertion point that includes only paragraphs styled Heading 1. To use this example, run it from the ThisDocument class in a document-level project.

private void DocumentTablesOfContents()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "Heading 1";
    this.Paragraphs[2].Range.Text = "Heading 2";

    object Style1 = Word.WdBuiltinStyle.wdStyleHeading1;
    this.Paragraphs[1].set_Style(ref Style1);

    object Style2 = Word.WdBuiltinStyle.wdStyleHeading2;
    this.Paragraphs[2].set_Style(ref Style2);

    object HeadingLevel = 1;
    this.TablesOfContents.Add(this.Application.Selection.Range,
        ref missing, ref HeadingLevel, ref HeadingLevel,
        ref missing, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing);
}
Private Sub DocumentTablesOfContents()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "Heading 1"
    Me.Paragraphs(2).Range.Text = "Heading 2"

    Dim Style1 As Object = Word.WdBuiltinStyle.wdStyleHeading1
    Me.Paragraphs(1).Style = Style1

    Dim Style2 As Object = Word.WdBuiltinStyle.wdStyleHeading2
    Me.Paragraphs(2).Style = Style2

    Dim HeadingLevel As Object = 1
    Me.TablesOfContents.Add(Me.Application.Selection.Range, , HeadingLevel, _
        HeadingLevel)
End Sub 

Applies to