Opening Visio with VBA

T

Tom Bunzel

Hi,

(I posted this on the 2003 beta site but this is probably
a better venue. Sorry for duplication).

I am trying to send data from Excel to Visio, and can do
it if I open Visio manually first (as ActiveDocument), but
can't seem to get a Visio file to open from scratch.

I have scoured the dev books and tried different code
combinations like what I am adding below. I have set my
references in the VBA Editor and I am using the beta
version for 2003.

Essentially I want to open a Visio file (template or
drawing), make stuff happen, and then display the page
full screen.
If anyone can help me on this I would appreciate it.

-- Tom

Dim AppVisio As Visio.Application
Dim FileVisio As Visio.Document
Dim PageVisio As Visio.Page

Set AppVisio = GetObject(, "Visio.Application")

AppVisio.Documents.Open ("C:\Documents and
Settings\Tom\Desktop\Projects\stuff.vsd")

or
AppVisio.Document.Open ("C:\Documents and
Settings\Tom\Desktop\Projects\stuff.vsd")
 
A

al

they used to ship this as an example



' ---------------------------------------------------------
----------------
' Copyright (C) 1999 Visio Corporation
'
' You have a royalty-free right to use, modify, reproduce
and distribute
' the Sample Application Files (and/or any modified
version) in any way
' you find useful, provided that you agree that Visio has
no warranty,
' obligations or liability for any Sample Application
Files.
' ---------------------------------------------------------
----------------

Sub main()

'This subroutine demonstrates getting the open instance of
Visio, or creating a
'new instance of Visio if one does not exist. It also
demonstrates creating
'a new blank drawing (if no documents are open in Visio),
or setting a reference
'to the currently active document in Visio if there are
documents open in the
'the current instance of Visio


Dim visApp As Visio.Application 'Visio Application Object
Dim visDoc As Visio.Document 'Visio Document Object

On Error Resume Next

'Get the open instance of Visio
Set visApp = GetObject(, "Visio.Application")

If (visApp Is Nothing) Then
'there is no open instance of Visio, Create one
Set visApp = CreateObject("Visio.Application")
'Add a new blank drawing page
Set visDoc = visApp.Documents.Add("")
Else
'There was an open instance of Visio
If visApp.Documents.Count = 0 Then
'if there are no open documents in this instance
of Visio,
'Add a new blank drawing
Set visDoc = visApp.Documents.Add("")
Else
'otherwise, get the currently active document
Set visDoc = visApp.ActiveDocument
End If
End If

'Show a form and put the name of the active document in a
text box
Load frmMain

frmMain.Text1.Text = visDoc.Name

frmMain.Show vbModeless


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top