Open Method [Visio 2003 SDK Documentation]

As it applies to the Documents collection.

Opens an existing file so that it can be edited.

docObjRet = docsObj**.Open** (FileName)

docObjRet     A Document object that represents the file that was opened.

docsObj     Required. An expression that returns the Documents collection to receive the opened file.

FileName     Required String. The name of a file to open.

Version added

2.0

Remarks

When you use the Open method to open a Document object, it opens a Microsoft Visio file as an original. Depending on the file extension, the Open method opens a drawing (.vsd), a stencil (.vss), a template (.vst), a workspace (.vsw), an XML drawing (.vdx), an XML stencil (.vsx), or an XML template (.vtx). You can also use this method to open and convert non-Visio files to Visio files. If the file does not exist or the file name is invalid, no Document object is returned and an error is generated.

If you pass a valid stencil (.vss) file name, the original stencil file opens. Starting with Microsoft Office Visio 2003, only author="SaulC" time="20050706T154647-0800" data="custom ("user-createdauthor="SaulC" time="20050706T154651-0800" data=")" stencils are editable. By default, Visio stencils author="SaulC" time="20050706T154718-0800" data="(stencils that are shipped on the Microsoft Office Visio CD)" are not editable. author="SaulC" time="20050706T154612-0800" data="However, by setting the <bterm>AllowEditing</bterm> property of the stencil's <bterm>Window</bterm> object to <bterm>True</bterm>, you can override this behavior to allow editing of built-in stencils. "Unless you want to create or edit the masters, open a stencil as read-only.

As it applies to the Master object.

Opens an existing master so that it can be edited.

masterObjCopy = masterObj**.Open**

masterObjCopy    A temporary copy of masterObj.

masterObj     Required. An expression that returns a Master object to be edited.

Version added

4.1

Remarks

You can use the Open method for a Master object in conjunction with the Close method to reliably edit the shapes and cells of a master. In previous versions of Visio, you could edit a Master object's shapes and cells, but the changes were not pushed to instances of the master, and alignment box information displayed when instancing the edited master was not correct.

To edit the shapes and cells of a Master object from a program

  1. Open the Master object for editing by using masterObjCopy = masterObj.Open. This code fails if there is a drawing window open into masterObj or if other programs already have masterObj open. If the Open method succeeds, masterObjCopy is a copy of masterObj.
  2. Change any shapes and cells in masterObjCopy, not masterObj.
  3. Close the Master object by using masterObjCopy.Close. The Close method fails if masterObjCopy isn't a Master object that resulted from a prior masterObj.Open call. Otherwise, the Close method merges the changes made in step 2 from masterObjCopy back into masterObj. It also updates all instances of masterObj to reflect the changes and update information cached in masterObj. If masterObj.IconUpdate isn't visManual (0), the Close method updates the icon shown in the stencil window for masterObj to depict an image of masterObjCopy.

If you change the shapes and cells of a master directly, as opposed to opening and closing the master as described in the procedure above, the effects listed in step 3 don't occur.

A program that creates a copy of a masterObj for editing should both close and release the copy. Microsoft Visual Basic typically releases it automatically. However, when you are coding in C or C++, you must explicitly release the copy, just as you would for any other object.

Note  Starting with Microsoft Office Visio 2003, only author="SaulC" time="20050706T162933-0800" data="custom ("user-createdauthor="SaulC" time="20050706T162937-0800" data=")" stencils are editable. By default, Visio stencils author="SaulC" time="20050706T162945-0800" data="(stencils that are shipped on the Microsoft Office Visio CD)" are not editable. author="SaulC" time="20050706T162957-0800" data="However, by setting the <bterm>AllowEditing</bterm> property of the stencil's <bterm>Window</bterm> object to <bterm>True</bterm>, you can override this behavior to allow editing of built-in stencils."

Example

As it applies to the Documents collection.

This Microsoft Visual Basic for Applications (VBA) macro shows how to open a blank document, a new document based on a template, and an existing document.

Before running this macro, replace path\filename with the path to and file name of a valid template file (.vst) on your computer.

Public Sub OpenDocument_Example()
 
    Dim vsoDocument As Visio.Document 

    'Open a blank document (not based on a template).
    Set vsoDocument = Documents.Add("") 

    'Open a new document based on a template.
    Set vsoDocument = Documents.Add _ 
    ("path\filename") 

    'Open an existing document.
    Set vsoDocument = Documents.Open _ 
    ("path\filename") 

End Sub  

    

As it applies to the Masters collection.

This Microsoft Visual Basic for Applications (VBA) macro shows how to open a Master object for editing. It opens a copy of a master from the document stencil and changes the fill foreground color of the master and all shapes in the drawing derived from the master.

Before running this macro, close all open Visio documents. Then, click New to open a new document based on no template. Click the Rectangle tool, and draw a rectangle on the drawing page. Open the document stencil (on the File menu, point to Shapes, and click Show Document Stencil), and then drag the rectangle shape onto the document stencil to create a master. Finally, drag several copies of the rectangle master onto the drawing page.

Public Sub OpenMaster_Example()

    Dim vsoMaster As Visio.Master
    Dim vsoMasterCopy As Visio.Master
    Dim vsoShape As Visio.Shape
    Dim vsoCell As Visio.Cell

    Set vsoMaster = Visio.Documents.Masters(1)
    Set vsoMasterCopy = vsoMaster.Open

    Set vsoShape = vsoMasterCopy.Shapes.Item(1)

    Set vsoCell = vsoShape.CellsU("FillForegnd")
    vsoCell.Formula = 9

    vsoMasterCopy.Close

End Sub  

    

Applies to | Documents collection | Master object

See Also | Close method | Drop method | OpenEx method