Add related procedures in class Subdocument (Word VBA)

This page presents procedures from class Subdocument related to the theme Add: Subdocuments.AddFromFile and Subdocuments.AddFromRange

Subdocuments.AddFromFile

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

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

Syntax : expression.AddFromFile (Name, ConfirmConversions, ReadOnly, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate)

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

Arguments

The following argument is required

Name (String) - The file name of the subdocument to be inserted into the master document.

The following arguments are optional

ConfirmConversions (Boolean) - True to confirm file conversion in the Convert File dialog box if the file isn't in Word format.

ReadOnly (Boolean) - True to insert the subdocument as a read-only document.

PasswordDocument (String) - The password required to open the subdocument if it is password protected.

PasswordTemplate (String) - The password required to open the template attached to the subdocument if the template is password protected.

Revert (Boolean) - 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 (Document) - The password required to save changes to the document file if it is write-protected.

WritePasswordTemplate (String) - The password required to save changes to the template attached to the subdocument if the template is write-protected.

Subdocuments.AddFromRange

Creates one or more subdocuments from the text in the specified range and returns a SubDocument object.

The Range argument must begin with one of the built-in heading level styles (for example, Heading 1). Subdocuments are created at each paragraph formatted with the same heading format used at the beginning of the range. Subdocument files are saved when the master document is saved and are automatically named using text from the first line in the file.

Syntax : expression.AddFromRange (Range)

Range: The range used to create one or more subdocuments.

ActiveDocument.ActiveWindow.View.Type = wdMasterView 
ActiveDocument.SubDocuments.AddFromRange Range:=Selection.Range