VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Calling VBA macro from command line or button

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
13236 Views, 4 Replies

Calling VBA macro from command line or button

I'm a little new to VBA programming and customization and I'm having trouble with something.  I wrote a VBA macro (in its own module) but the only I know to call it is with the run VBA dialog box (VBARUN command) selecting it from the list.

 

I am wondering if there is a way to create a unique command name for it so I can call it directly from the command line, or if I can create a button to call it from my custom tool pallette.  Thanks for any help.

 

Caleb B

4 REPLIES 4
Message 2 of 5
andrewpuller3811
in reply to: Anonymous

(defun C:HB ()
(vl-load-com)
(vl-vbarun "HotButton2010.dvb!HBMain")
(princ)
)

 

I have the above in my acaddoc.lsp

 

This defines a command HB. When run on the command line it loads the vba file HotButton2010.dvb and run the sub HBMain from within that file.

 

In this case the acaddoc.lsp and vba file are stored in one of autocads support folders, preferrably the first folder in the list.

 

Before you get too far into vba, you might want to look at vb .net, or c#.net as vba in autocad is on it's way out.

As far as I know, 2011 is the last version to support vba.



If a post provides a fix for your issue, click on "Accept as Solution" to help other users find solutions to problems they might have that are similar to yours.

Andrew Puller
Maitland, NSW, Australia
Windows 10 Enterprise 64bit
Intel core i7 11800 @ 2.30 GHz with 32GB Ram
Civil 3d 2021
Message 3 of 5
Anonymous
in reply to: Anonymous

Put the following in the Macro definition of a toolbar button:

 

^C^C_.-vbarun;"C:/MyPath/MyMacroFilename.dvb!MyModuleName.MyRoutineName";

Message 4 of 5
Anonymous
in reply to: Anonymous

This is also what I use, however I just came across a few toolbar buttons that weren't working when I changed to a newer directory.  I was confused and frusterated for a while.  The last thing I tried was to shorten the lengths of the sub procedure names, and it worked!

 

I have a feeling there is some path length limitation for the path in quotes below, however I could be wrong I'm only guessing.  The path length of 111 characters worked for me, but the length of 133 characters didn't.

 

^C^C_.-vbarun;"C:/MyPath/MyMacroFilename.dvb!MyMod​uleName.MyRoutineName";

Message 5 of 5
Anonymous
in reply to: Anonymous

The -vbarun; etc. line is how to do it. You should know that it is possible to pass arguments in that very same line to your VBA. Thus you can have that VBA act upon the arguments passed to it. So keep that in mind as a way to leverage your VBA functionality.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost