Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Nov 2004
    Location
    Ottawa, Ontario, Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling VBA sub from TCL (Excel VBA)

    I often call a VBA sub in one Excel workbook from another. What I'd like to do is call from TCL but my VBA routines don't seem to be accessible. The only routines I can call from TCL are the builtin Excel object methods. Any ideas?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Calling VBA sub from TCL (Excel VBA)

    I'm probably not qualified to reply, since I don't have the slightest idea what TCL is.

    In Excel itself, you can call procedures in other workbooks using

    Application.Run "MyWorkbook.xls!MyMacro"

    or

    Application.Run "MyWorkbook.xls!MyProc", 37

    (the procedure MyProc takes a numeric argument). Can you adapt this in TCL, replacing Application by an Excel.Application object?

  3. #3
    New Lounger
    Join Date
    Nov 2004
    Location
    Ottawa, Ontario, Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling VBA sub from TCL (Excel VBA)

    Thanks for the hint
    TCL stands for Tool Command Language. It's a powerful scripting language (with widgets) available on almost all platforms.

    The hint helped but I'm not quite there yet. I'm able to call subs which are defined in Modules but not in ThisWorkbook. This is not a big problem. I have not been able to provide an argument to my Excel sub. This is likely just a TCL syntax issue. I'll report back if and when I solve it.

    BTW, if you want to play with TCL just go to http://www.activestate.com/ and get ActiveTcl.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Calling VBA sub from TCL (Excel VBA)

    Also see if <!post=this post,216448>this post<!/post> from Jan Karel <!profile=Pieterse>Pieterse<!/profile> (where he advised me I was wrong!) is of help. I'm not sure if ThisWorkbook can be addressed the same way, but as Jan Karel explains its better to only use ThisWorkbook for its Events, and I can also advise you that User Defined worksheet Functions (UDFs) cannot be placed in ThisWorkbook, thogh that's proibably not relevant for you.
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling VBA sub from TCL (Excel VBA)

    Hi Quentin,

    I haven't used Tcl, (though I've done a bit of work with Expect), but I found the following link that might be of use:
    http://mini.net/tcl/4472

    Hope this helps.

  6. #6
    New Lounger
    Join Date
    Nov 2004
    Location
    Ottawa, Ontario, Canada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calling VBA sub from TCL (Excel VBA)

    Thanks to the help received, I've managed to run Excel VBA subs from TCL. The Sub must be defined (non-private) in a VB module. Subs in ThisWorkbook or Sheets are not visible.
    For those interetsted, here is the basic TCL access code to a sub MySub with argument MyArg

    set application [::tcom::ref createobject "Excel.Application"]
    $application Run MySub [expr MyArg]

    Excel runs completely hidden.

Posting Permissions

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