Condividi tramite


DocumentBase.Subdocuments Property

Definition

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

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

Property Value

A Subdocuments collection that represents all the subdocuments in the document.

Examples

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

Applies to