DocumentBase.Subdocuments 属性

定义

获取一个 Subdocuments 集合,该集合表示文档中的所有子文档。

public Microsoft.Office.Interop.Word.Subdocuments Subdocuments { get; }

属性值

Subdocuments

一个 Subdocuments 集合,表示文档中的所有子文档。

示例

下面的代码示例将标题1样式应用于所选内容中的第一个段落,然后为所选内容创建一个子文档。 然后,该代码将显示一条消息,其中显示文档中的子文档数。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。

private void DocumentSubdocuments()
{
    object style = Word.WdBuiltinStyle.wdStyleHeading1;

    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Text = "This is sample text.";
    Word.Range currentRange = this.Paragraphs[1].Range;
    currentRange.Select();
    this.Application.Selection.Paragraphs[1].set_Style(ref style);

    this.Subdocuments.Expanded = true;
    this.Subdocuments.AddFromRange(Application.Selection.Range);

    MessageBox.Show("Total subdocuments: " + this.Subdocuments.Count.ToString());
}
Private Sub DocumentSubdocuments()
    Dim style As Object = Word.WdBuiltinStyle.wdStyleHeading1

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Text = "This is sample text."
    Dim currentRange As Word.Range = Me.Paragraphs(1).Range
    currentRange.Select()
    Me.Application.Selection.Paragraphs(1).Style = style

    Me.Subdocuments.Expanded = True
    Me.Subdocuments.AddFromRange(Application.Selection.Range)

    MessageBox.Show("Total subdocuments: " & Me.Subdocuments.Count.ToString())
End Sub 

适用于