Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running VBA macro at startup. 1

Status
Not open for further replies.

LumpoDelMagnifico

Electrical
Sep 22, 2004
35
0
0
US
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
 
Replies continue below

Recommended for you

Do you want a toolbar with your code attached available each time you start autocad? So that by clicking the toolbar it causes the macro to run?

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.
 
I already load the VBA Apps from the startup suite. I am using the following sub to make the toolbar and button.

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?
 
I either do not understand the question or I can not help you.

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?
 
I want to have a button that runs a VBA macro when clicked. I don't really care if I have to run this macro(Although it would increase portability) or I have to set it up in autocad. The code slice above creates a new toolbar, adds one button to it and docks it to the top left of the toolbars It also assigns the button to execute a VBA sub called "Main".
 
Ok then create a new toolbar and put any button on it you want. Right click the toolbutton just placed on your toolbar and select properties. You can then edit to suit.
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.
 
Check out
ACAD.DVB in the autocad2005 help file

use this at the help-->index:
Visual Basic for Applications, DVB files
 
Try putting this in your acad.lsp file.

(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!!
 
Status
Not open for further replies.
Back
Top