Run Macro On VBA Project Load

Run Macro On VBA Project Load

Anonymous
Not applicable
2,387 Views
2 Replies
Message 1 of 3

Run Macro On VBA Project Load

Anonymous
Not applicable

Hello,

I have a VBA project which contains several macros, but one in particular loads a toolbar which can run all of the others. Currently I am loading in the VBA project and running the toolbar loading macro manually. From looking around I realize it is possible to automate all of this on startup or drawing creation by using a separate acad.dvb file or using LISP, but I am not necessarily interested in automating the Project Loading. What I would be particularly interested in knowing is if there is some way to run that toolbar loading macro (or some small amount of code) once the VBA project is loaded.

 

Essentially the behavior I am trying to spoof, is that of an old Lisp routine which upon application load would bring in a customization file automatically. If the short answer is no, there's no way to do that, I will find out what else will work, but anyone knows of a way to get that behavior, I would welcome the suggestions.

 

Thanks,

Brandon

0 Likes
Accepted solutions (1)
2,388 Views
2 Replies
Replies (2)
Message 2 of 3

ambrosl
Autodesk
Autodesk
Accepted solution

What method(s) are using to load the VBA project?  There is no built in function such as Initialize or Init that is executed upon the loading of a VBA module in AutoCAD, but Document related events are registered during the loading of a VBA module.  With a Document event, it is plausible that you might be able to accomplish what you are trying to do.  For example, you could watch for the end of the VBALOAD or -VBALOAD commands and then do something which could be the loading of the toolbar.  The event handler must be defined in the ThisDrawing class module of the VBA project.

 

The following example watches for the end of the VBALOAD or -VBALOAD commands, and then displays a message box for each loaded DVB project file:

 

Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
  If CommandName = "VBALOAD" Or CommandName = "-VBALOAD" Then
    ' Test for toolbar here or just execute the code you want
    
    Dim VBEModel As VBE
    Set VBEModel = ThisDrawing.Application.VBE
   
    Dim oPrj As VBProject
   
    For Each oPrj In VBEModel.VBProjects
      MsgBox "Project Name: " & oPrj.Name & vbLf & _
             "File Name: " & oPrj.FileName
    Next oPrj
  End If
End Sub



Lee Ambrosius
Senior Principal Content Experience Designer
For additional help, check out the AutoCAD Developer Documentation
0 Likes
Message 3 of 3

Anonymous
Not applicable

Lee,

 

Thank you so much for your response, it had not occurred to me to check each command. Turned out I was using the APPLOAD command and sure enough once I plugged that into your snippet and tracked down my project I was able to run my toolbar Macro. 10/10. Thanks very much.

 

Brandon

0 Likes