Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a Visio function from an Excel macro

Status
Not open for further replies.

opeth49

Technical User
Nov 9, 2004
5
0
0
CA
Hi,
I need to create a macro in Excel that would open a Visio drawing and run a function in this drawing, with parameters.
I believe this is fairly easy but it's something I've never done before. Any help would be appreciated.
 
Hi opeth49,

I've not done this before and I am running Visio 5 (which has VBA but is pre-Microsoft) and this works for me - with a reference to the Visio Type Library set.

Code:
[blue]Dim v as Visio.Application
Dim vdoc as Visio.Document
Set v = CreateObject("Visio.Application")
Set vdoc = v.Documents.Open("[i]mypath\mydrawing.vsd[/i]")
vdoc.ExecuteLine "MyVisioProc myparameter"
vdoc.Close
v.Quit
Set vdoc = Nothing
Set v = nothing[/blue]

where MyVisioProc is in a module in mydrawing.

The ExecuteLine runs a VBA statement as though it were entered in the (Visio) Immediate window.

It is possibly different with later releases of Visio - which I believe come with VBA 6 as standard.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at [url=http://www.vbaexpress.
 
Nice this works perfectly! Thanks Tony!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top