Creating a Visio Document

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, blank document

  1. Get the Documents property of the Application object to get its Documents collection.
  2. Use the Add method of the Documents collection to create the document.
  3. 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 create a new document from a template

  1. Get the Documents property of the Application object to get its Documents collection.
  2. Use the Add method of the Documents collection to create the document.
  3. 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.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net