Results 1 to 3 of 3

Thread: Solved: Running an external script

  1. #1
    VBAX Newbie
    Joined
    Sep 2008
    Posts
    2
    Location

    Solved: Running an external script

    Hi,

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

    [vba]
    Attribute VB_Name = "External"
    Sub External()
    OK = MsgBox("External", vbOKCancel)
    End Sub
    [/vba]

    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.
    [vba]
    Private Sub Project2Flowchart()
    Visio.Application.Vbe.ActiveVBProject.VBComponents.Import ("C:\External.bas")
    Call External.External
    End Sub
    [/vba]

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,446
    Location
    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

    [vba]


    Public Function CallExternal()
    Call External.External
    End Function
    [/vba]

    then in your procedure back in the original module, use

    [vba]

    Private Sub Project2Flowchart()
    Visio.Application.Vbe.ActiveVBProject.VBComponents.Import ("C:\External.bas")
    Call CallExternal
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Sep 2008
    Posts
    2
    Location
    Hi xld,

    That's great - works a treat.

    Thanks very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •