PDA

View Full Version : Solved: Running an external script



scaiels
09-22-2008, 04:45 AM
Hi,

I have an application that creates a text file called external.bas containing this . . .


Attribute VB_Name = "External"
Sub External()
OK = MsgBox("External", vbOKCancel)
End Sub


In reality, it's a script to create a flow chart in Visio, but I have a problem even with the script above.

In visio, I have this script.

Private Sub Project2Flowchart()
Visio.Application.Vbe.ActiveVBProject.VBComponents.Import ("C:\External.bas")
Call External.External
End Sub


I know that's not the orthodox way of forming the code, but the method I?m using to create the codes needs to use the minimum number of lines.

The first time I run the script, the external .bas file is successfully imported into a module called external, but the ?call external.external? line fails with an ?Object Required? error. If I just run it again, it fails again.

However, if I debug, and break out of the script, then run it again. Or retype the ?call external.external? line, then it works fine.

It seems I have to somehow ?refresh? the script parser for it to find the newly imported module. Is there any code that will do that for me?

As you can tell from my vba vocabulary, I?m very new to this and by no means a coder.

Any help very much appreciated.

Thanks,
Steve.

Bob Phillips
09-22-2008, 06:00 AM
The only way I could get it to run (I had Option Explicit, so it errorred at compile for me), was to add another module and add this code in there




Public Function CallExternal()
Call External.External
End Function


then in your procedure back in the original module, use



Private Sub Project2Flowchart()
Visio.Application.Vbe.ActiveVBProject.VBComponents.Import ("C:\External.bas")
Call CallExternal
End Sub

scaiels
09-22-2008, 06:09 AM
Hi xld,

That's great - works a treat.

Thanks very much :beerchug: