Running VBA Macro with Parameter from Autocad Command line

Discussion in 'AutoCAD' started by Dave Mikolaitis, Jul 1, 2003.

  1. How do you run a vba macro using a variable as a command line item?
    I would expect it would be something like this, but it does not work.

    -vbarun SiteMenu.SetSiteMenu 5

    Where SiteMenu.SetSiteMenu is the macro and 5 is the variable that I want to
    pass.

    The sub code looks like

    Sub SetSiteMenu(intMenu as Integer)

    Exit
     
    Dave Mikolaitis, Jul 1, 2003
    #1
  2. I don't think you can run a macro that takes parameters from the command line.
     
    Mark_Abercrombie, Jul 1, 2003
    #2
  3. Dave Mikolaitis

    Tim Jendro Guest

    I found this a while ago in the Autodesk AutoCAD Knowledge base:

    No, it is not possible to pass parameters from the program directly into a
    VBA macro. However, you can use the GetString function in VBA and the
    AutoLISP® (command) function to pass data. This example shows how to pass
    data using VBA and AutoLISP to a VBA macro:

    In the MODULE:


    Public Param1, Param2 As StringSub MyMacro()Param1 =
    ThisDrawing.Utility.GetString(False) Param2 =
    ThisDrawing.Utility.GetString(False) 'Enter your code hereEnd
    SubThen call the VBA macro as:
    (command "-VBARUN" " MyMacro " "Argument1"
    "Argument2")--------------------------------I have used this and it works
    very well.Hope it helps.
     
    Tim Jendro, Jul 1, 2003
    #3
  4. Dave Mikolaitis

    Ken Hutson Guest

    P.S.
    I have also used used USERS1 - USERS5 to hold strings so that VBA can pick
    them up.
    Ken
     
    Ken Hutson, Jul 1, 2003
    #4
  5. Dave Mikolaitis

    Tom Craft Guest

    The getstring method will work, but you can also use lisp setq to store the
    values in lisp variables and then recover them in VB/VBA using the Vlax class. I
    use this sometimes to 'park' values in lisp when my VB program will not always
    know which form will create and/or retrieve the data. Saves declaring a global
    variable for an 'on the fly' value.

    Tom
     
    Tom Craft, Jul 2, 2003
    #5
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 (here). After that, you can post your question and our members will help you out.