Subdocuments.AddFromFile method (Word)

Adds the specified subdocument to the master document at the start of the selection and returns a Subdocument object.

Syntax

expression. AddFromFile( _Name_ , _ConfirmConversions_ , _ReadOnly_ , _PasswordDocument_ , _PasswordTemplate_ , _Revert_ , _WritePasswordDocument_ , _WritePasswordTemplate_ )

expression Required. A variable that represents a 'Subdocuments' collection.

Parameters

Name Required/Optional Data type Description
Name Required String The file name of the subdocument to be inserted into the master document.
ConfirmConversions Optional Variant True to confirm file conversion in the Convert File dialog box if the file isn't in Word format.
ReadOnly Optional Variant True to insert the subdocument as a read-only document.
PasswordDocument Optional Variant The password required to open the subdocument if it is password protected.
PasswordTemplate Optional Variant The password required to open the template attached to the subdocument if the template is password protected.
Revert Optional Variant Controls what happens if Name is the file name of an open document. True to insert the saved version of the subdocument. False to insert the open version of the subdocument, which may contain unsaved changes.
WritePasswordDocument Optional Variant The password required to save changes to the document file if it is write-protected.
WritePasswordTemplate Optional Variant The password required to save changes to the template attached to the subdocument if the template is write-protected.

Return value

Subdocument

Remarks

If the active view isn't either outline view or master document view, an error occurs.

Example

This example adds a subdocument named "Subdoc.doc" to the active document.

ActiveDocument.ActiveWindow.View.Type = wdMasterView 
ActiveDocument.Subdocuments.AddFromFile _ 
 Name:="C:\Subdoc.doc"

This example adds a password-protected subdocument named "Subdoc.doc" to the active document on a read-only basis and sets the PasswordDocument parameter to a String variable.

Selection.Range.Subdocuments.AddFromFile Name:="C:\Subdoc.doc", _ 
 ReadOnly:=True, PasswordDocument:=strPassword

See also

Subdocuments Collection Object

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.