Subdocument object (Word)

Represents a subdocument within a document or range. The Subdocument object is a member of the Subdocuments collection. The Subdocuments collection includes all the subdocuments in the a range or document.

Remarks

Use Subdocuments (Index), where Index is the index number, to return a single Subdocument object. The following example displays the path and file name of the first subdocument in the active document.

If ActiveDocument.Subdocuments(1).HasFile = True Then 
 MsgBox ActiveDocument.Subdocuments(1).Path & _ 
 Application.PathSeparator & _ 
 ActiveDocument.Subdocuments(1).Name 
End If

Use the AddFromFile or AddFromRange method to add a subdocument to a document. The following example adds a subdocument named "Setup.doc" at the end of the active document.

ActiveDocument.Subdocuments.Expanded = True 
Selection.EndKey Unit:=wdStory 
Selection.InsertParagraphBefore 
ActiveDocument.Subdocuments.AddFromFile Name:="C:\Temp\Setup.doc"

The following example applies the Heading 1 style to the first paragraph in the selection and then creates a subdocument for the contents of the selection.

Selection.Paragraphs(1).Style = wdStyleHeading1 
With ActiveDocument.Subdocuments 
 .Expanded = True 
 .AddFromRange Range:=Selection.Range 
End With

See also

Word Object Model Reference

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.