How to call a VBA macro in Visio by Automation?

P

Petter

Hi!

I am opening a Visio Template (*.vst) with Automation.
How can I call a VBA macro that is included in the *.vst file using
Automation?

Best regards from Petter
 
J

JuneTheSecond

OpenEx method might be used to open Visio template.
This is an example to make new drawing from a template.
Documents.OpenEx "C:\Program Files\Microsoft
Office\Visio11\1041\BLOCK_M.VST", visOpenCopy
 
P

Petter

Thank you, but opening and drawing is not a problem.
My problem is to call a VBA Macro in a module inside the document. I have
tried doc.ExecuteLine() without success. Can you help?

Best regards from Petter
 
J

JuneTheSecond

Sorry for my miss understanding, in order to run a macro when you
double-click the icon of the template and make a new drawing from the
template, put next code on "ThisDocument" of the template,
Private Sub Document_DocumentCreated(ByVal doc As IVDocument)
testmacro
End Sub
and put "testmacro" at a "module" of the template.
 
P

Petter

Thank you, but my question was not clear. What I ment was:

1. I open a *.vst file from another program (Excel VBA or a C++ program)
with Automation
2. I can draw things with automation - no problem.
3. But inside the open *.vst file I have a VBA macro in for example Module
1:
Public Sub MyDoSomething()
MsgBox "Hello"
End Sub
How can I start the MyDoSomething from another program?
From another program I have tried docOvj.ExecuteLine( "Call
MyDoSomething" ) but it does not work.

----------------
Based on your answer I have a related question:
Document_DocumentCreated(ByVal doc As IVDocument) is called when a *.vsd
file is opened manually,
but not when my Automation code opens a *.vst file like this (using C++
#import):
m_app.CreateInstance(L"Visio.Application");
m_docObj = m_app->Documents->Add( _bstr_t(sFNameVST) );

Is there a way similar to using Document_DocumentCreated() in this case?

Best regards from Petter
 
J

JuneTheSecond

for part 1, I dont know how to run the macor in the Visio template, perhaps,
there is noway other than open or create event.
for part 2, your code seems going to open vst file itself, but not copy.
If you wish to open vst file iself, use Document_DocumentOpened procedure in
place of Document_DocumentCreated.
 
P

Petter

Thank you very much - Document_DocumentCreated solved my problem!

Best regards from Petter
 

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