Udostępnij za pośrednictwem


Document.TablesOfContents Property (2007 System)

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

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property TablesOfContents As TablesOfContents
'Usage
Dim instance As Document 
Dim value As TablesOfContents 

value = instance.TablesOfContents
[BrowsableAttribute(false)]
public TablesOfContents TablesOfContents { get; }
[BrowsableAttribute(false)]
public:
property TablesOfContents^ TablesOfContents {
    TablesOfContents^ get ();
}
public function get TablesOfContents () : TablesOfContents

Property Value

Type: TablesOfContents
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.

This example is for a document-level customization.

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
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);
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace