3 4
After you get an Application object that represents a Microsoft Visio instance, the next step is to create or open a document.
To create a new document without basing it on a template, supply a null string ( "" ) as an argument to Add. For example, the following statement creates a new, blank document:
Set docObj = appVisio.Documents.Add("")
A document created in this way has the Visio default drawing scale, styles, and other document settings. No stencils are opened.
To base the new document on a template, supply the file name of that template as an argument to Add. For example, the following statement creates a new document based on the Basic Diagram template provided with Visio:
Set docObj = appVisio.Documents.Add("Basic Diagram.vst")
If you don't specify a path with the template file name, the Visio engine searches the folders shown in the Templates box on the File Paths tab (on the Tools menu, click Options). To find out the current path settings, get the Application object's TemplatePaths property. For details about using the File Paths tab, see theMicrosoft Visio Developer Reference (on the Help menu, click Developer Reference).
The Application object has a corresponding property for each of the fields on the File Paths tab in the Options dialog. For example, the TemplatePaths property corresponds to the Templates box on the tab. You can get any of these properties to find the current path, or you can set the property to change the path. For details, see the Microsoft Visio Developer Reference (on the Help menu, click Developer Reference).
Application object properties that correspond to File Paths tab settings
File Path field | Property |
---|---|
Drawings | DrawingPaths |
Templates | TemplatePaths |
Stencils | StencilPaths |
Help | HelpPaths |
Add-ons | AddonPaths |
Start-up | StartupPaths |
Filters | FilterPaths |
In the previous example, the new document has the drawing scale, styles, and document settings defined in the Basic Diagram template. This template has a stencil—Basic Shapes—in its workspace, so creating the document also opens that stencil as read-only in a stencil window and adds the stencil file to the Documents collection of the instance.