Running VBA macro at startup.
Running VBA macro at startup.
(OP)
Can anyone tell me how to run a VBA macro every time I launch AutoCad? I have a Macro button that I want to add to the toolbar. I use a VBA sub called "AddToolbar" but the next time I Launch Acad the toolbar button is gone. So, what I want to do is set autucad to run "AddToolbar" everytime I launch acad





RE: Running VBA macro at startup.
autocad can preload your code at startup.
On the menu bar go to TOOLS--->load application
(or APPLOAD at the command prompt)
Look for the label 'STARTUP SUITE' and click the CONTENTS
button. Click ADD and browse to the location of your routine.
You can then create a toolbar (docked or floating)and assign the code to that button. Then the routine will
run each time you click the toolbar you just created.
RE: Running VBA macro at startup.
Sub addtoolbar()
Dim mytoolbar As AcadToolbars
Dim MyButton As AcadToolbar
Dim objmenugroup As AcadMenuGroup
Dim newbutton As AcadToolbarItem
Set objmenugroup = ThisDrawing.Application.MenuGroups.Item(0)
Set mytoolbar = objmenugroup.Toolbars
Set MyButton = mytoolbar.Add("done1")
Set newbutton = MyButton.AddToolbarButton(0, "DONE", "O", "-vbarun main ")
MyButton.Visible = True
MyButton.Dock acToolbarDockTopRight
newbutton.SetBitmaps "C:/DONE/DONE.bmp", "C:/DONE/DONE.bmp"
End Sub
But, The next time I launch autocad, the button is gone. I would really like to just run this macro at startup. Any ideas how I can do that?
RE: Running VBA macro at startup.
I think that the startup suite merely loads the routine but does not execute that code. As far as I know, to execute the code you would have to have it assigned to a button or enter something at the command line.
Does the code have to create the toolbar button or do you want the code assigned to a button so that when you click it your vba routine runs?
RE: Running VBA macro at startup.
RE: Running VBA macro at startup.
Add the appropriate code that calls your routine
in the macro section. What i do is in the macro code area put a command to load the routine followed by the command to execute the code for those seldom used routines that i do not preload with the startup suite.
RE: Running VBA macro at startup.
RE: Running VBA macro at startup.
ACAD.DVB in the autocad2005 help file
use this at the help-->index:
Visual Basic for Applications, DVB files
RE: Running VBA macro at startup.
RE: Running VBA macro at startup.
RE: Running VBA macro at startup.
(defun S::STARTUP()
(command "_-vbarun" "updatetitleblock")
)
and replace "updatetitleblock" with your VBA project name.
I believe that you could also include the line "acvba.arx" in your acad.rx file, name your macro AcadStartup and put it in the acad.dvb file. Then it would load and run everytime you open a drawing or start a new one.
Let us know what works!!
RE: Running VBA macro at startup.