Expand Minimize

DocumentBase.Subdocuments Property

Gets a Subdocuments collection that represents all the subdocuments in the document.

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

public Subdocuments Subdocuments { get; }

Property Value

Type: Microsoft.Office.Interop.Word.Subdocuments
A Subdocuments collection that represents all the subdocuments in the document.

The following code example applies the Heading 1 style to the first paragraph in the selection and then creates a subdocument for the contents of the selection. The code then displays a message that shows the number of subdocuments in the document. To use this example, run it from the ThisDocument class in a document-level project.

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft