Announcements
Notice: Upload of PDF documents is currently unavailable across the Community due to an ongoing issue.

Running VBA Macro with Parameter from Autocad Command line

Running VBA Macro with Parameter from Autocad Command line

Anonymous
Not applicable
3,016 Views
5 Replies
Message 1 of 6

Running VBA Macro with Parameter from Autocad Command line

Anonymous
Not applicable
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
0 Likes
3,017 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
I don't think you can run a macro that takes parameters from the command line.
0 Likes
Message 3 of 6

Anonymous
Not applicable
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.
0 Likes
Message 4 of 6

Anonymous
Not applicable
Dave

You can't run a macro that takes parameters from the command line.

For single var's use the system var's USERx1-5, for complex informations
use dictionaries to exchange values between vba macros and menu-/lisp.

Cheers
--
Juerg Menzi
MENZI ENGINEERING GmbH, Switzerland
http://www.menziengineering.ch
0 Likes
Message 5 of 6

Anonymous
Not applicable
P.S.
I have also used used USERS1 - USERS5 to hold strings so that VBA can pick
them up.
Ken

"Dave Mikolaitis" wrote in message
news:[email protected]...
> 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
>
>
>
0 Likes
Message 6 of 6

Anonymous
Not applicable
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

Dave Mikolaitis wrote:

> 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
0 Likes