Documents.Add Method

Visio Automation Reference

Adds a new Document object to the Documents collection.

Version Information
 Version Added:  Visio 2.0

Syntax

expression.Add(FileName)

expression   A variable that represents a Documents object.

Parameters

Name Required/Optional Data Type Description
FileName Required String The type or file name of the document to add; if you do not include a path, Visio searches the folder or folders designated in the Application object's TemplatePaths property and all published templates, including published third-party templates.

Return Value
Document

Remarks

To create a new drawing based on no template, pass a zero-length string ("") to the Add method.

To create a new drawing based on a template, pass "templatename.vst" to the Add method. Visio opens stencils that are part of the template's workspace and copies styles and other settings associated with the template to the new document. If the template file name is invalid, no document is returned and an error is generated.

To create a new stencil based on no stencil, pass ("vss").

To open a copy of a stencil, pass ("stencilname.vss").

To open a copy of a drawing, pass ("drawingname.vsd").

ms425621.vs_note(en-us,office.12).gif  Note
Opening a copy of a stencil or drawing is equivalent to selecting Copy in the Open list box of the Open dialog box or using the OpenEx method with the visOpenCopy flag.

Example

The following macro shows how to add Document objects such as templates, stencils, and drawings to the Documents collection.

Before running this macro, replace Myfile.vsd with a valid .vsd file.

Visual Basic for Applications
  Public Sub AddDocument_Example() 
Dim vsoDocument As Visio.Document

'Add a Document object based on the Basic Diagram template.
Set vsoDocument = Documents.Add("Basic Diagram.vst") 

'Add a Document object based on a drawing (creates a copy of the drawing).
Set vsoDocument = Documents.Add("<em>Myfile.vsd</em>")

'Add a Document object based on a stencil (creates a copy of the stencil).
Set vsoDocument = Documents.Add("Basic Shapes.vss") 

'Add a Document object based on no template.
Set vsoDocument = Documents.Add("") 

End Sub

See Also