×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Running VBA macro at startup.

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.

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.

RE: Running VBA macro at startup.

(OP)
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?

RE: Running VBA macro at startup.

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?

RE: Running VBA macro at startup.

(OP)
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".

RE: Running VBA macro at startup.

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.

RE: Running VBA macro at startup.

(OP)
this works fine, Thanks WMO. I would still like to run a macro at startup though If anyone knows how to do this, let me know.

RE: Running VBA macro at startup.

Check out
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.

Have you tried using the (DEFUN S::Startup () section of your Acad.lsp file?

RE: Running VBA macro at startup.

(OP)
IFRs I am not sure how it would work. I have tried using the autolisp startup file to run a vba app but I just got an error. Do you have any idea how to do this?

RE: Running VBA macro at startup.

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!!

RE: Running VBA macro at startup.

(OP)
Thanks IFRS you rock!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources