Running a .bas file

S

Steve Caiels

Hi, I have an external process that creates a script in a text file. If I
paste it into the project editor, it runs fine and creates the desired flow.
But I'd like to run it directly from the .bas file.

In Excel you can use :

Excel.Application.VBE.ActiveVBProject.VBComponents.Import ("External.bas")
Excel.Application.Run ("External")

But I can't get the equivalent going in Visio.

Can anyone tell me how to execute a simple script like the one below, stored
in an external text file please?
……
Private Sub External()
OK = MsgBox("External", vbOKCancel)
End Sub
……

Thanks,
Steve.
 
J

John... Visio MVP

Steve Caiels said:
Hi, I have an external process that creates a script in a text file. If
I
paste it into the project editor, it runs fine and creates the desired
flow.
But I'd like to run it directly from the .bas file.

In Excel you can use :

Excel.Application.VBE.ActiveVBProject.VBComponents.Import ("External.bas")
Excel.Application.Run ("External")

But I can't get the equivalent going in Visio.

Can anyone tell me how to execute a simple script like the one below,
stored
in an external text file please?
……
Private Sub External()
OK = MsgBox("External", vbOKCancel)
End Sub
……

Thanks,
Steve.


Visio Corp was the first non Microsoft company to fully implement VBA and
since this is the VBA side rather than the Visio side, it should work he
same as in Excel.

What sort of error are you running in to?

John... Visio MVP
 
S

Steve Caiels

John... Visio MVP said:
Visio Corp was the first non Microsoft company to fully implement VBA and
since this is the VBA side rather than the Visio side, it should work he
same as in Excel.

What sort of error are you running in to?

John... Visio MVP

Hi John,
I have a text file called “external.bas†that contains just 3 lines.

Private Sub External()
OK = MsgBox("External", vbOKCancel)
End Sub

And the Visio script is

Private Sub cmdCreateFlowchart_Click()
Call Project2Flowchart
End Sub

Private Sub Project2Flowchart()

Visio.Application.Vbe.ActiveVBProject.VBComponents.Import ("C:\External.bas")
Visio.Application.Run ("External")

End Sub

Now I look into it more in Excel, I think both applications react to my
appalling script in a similar way, but tell me about their displeasure in
different ways!

In Excel, the first time I run the internal script after opening the
workbook, it works. Subsequent runs give Runtime error 1004 Cannot run the
macro “External†. It may not be available

In Visio, it doesn’t run at all and gives the Runtime error 438 Object does
not support this property or method. On inspection, I see there is no Run
property for visio.application.

But they both import the external script into a node of the “Module†branch.
So I guess I need to scrub the visio.application.run line and find out how
to run the module.

Regards,
Steve.
 
S

Steve Caiels

Hi John,

Thanks very much. I almost have it :)

On first run, the import is successful and the module "external" is created,
but it fails with “Runtime 424 Object Required†on the call external.external
line. It’s like I have to do a refresh or something to let it see the new
module?

But even if I run it again, it will fail with the same message. However, if
I retype the call external.external line before running it, it will work.

I really appreciate your help on this.

Thanks,
Steve.
 

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