How to: Open Visio Documents
There are two methods for opening existing Microsoft Office Visio documents: Open and OpenEx. The OpenEx method is identical to the Open method, except that it provides arguments in which the caller can specify how the document opens.
For details about the object model, see the VBA reference documentation for the Microsoft.Office.Interop.Visio.Documents.Open method and Microsoft.Office.Interop.Visio.Documents.OpenEx method.
Opening a Visio Document
To open a Visio document
Call the Microsoft.Office.Interop.Visio.Documents.Open method and supply the fully qualified path of the Visio document.
Dim docPath As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\test\MyDrawing.vsd" Me.Application.Documents.Open(docPath)
string docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\test\MyDrawing.vsd"; this.Application.Documents.Open(docPath);
Opening a Visio Document with Specified Arguments
To open a Visio document as read-only and docked
Call the Microsoft.Office.Interop.Visio.Documents.OpenEx method, supply the fully qualified path of the Visio document, and include the arguments you want to use—in this case, Docked and Read-only.
Dim docPath As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\test\MyDrawing.vsd" Me.Application.Documents.OpenEx(docPath, CShort(Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked) + CShort(Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenRO))
string docPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + @"\test\MyDrawing.vsd"; this.Application.Documents.OpenEx(docPath, ((short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked + (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenRO));
Compiling the Code
This code example requires the following:
- A Visio document named myDrawing.vsd must be located in a directory named Test in the My Documents folder (for Windows XP and earlier) or the Documents folder (for Windows Vista).
See Also
Tasks
How to: Create New Visio Documents