View Full Version : Run a Routine When Opening AutoCAD Drawing
MikeS
03-29-2005, 09:42 AM
Bear with me, I'm a beginner with VBA. What I want to do is run a VBA routine automatically each time an existing drawing is openned.
How???:help
Tommy
03-29-2005, 03:44 PM
Hi MikeS,
Welcome to VBAexpress! :hi:
In acad create a new project, follow the instructions below. Save the project. Then pick Tools -> Load Application, in the dialog box that appears look for Startup Suite, Pick the Contents Button, another dialog box will appear browse to the location you saved the project to and pick the project. Pick close and close. The next time you open acad and a drawing/create a new drawing it will run your code.
in a module named Module1
Sub RunThis()
'place code you want to run here
End Sub
in a class called Class1
Public WithEvents ACADApp As AcadApplication
Public Sub AcadApplication_Events()
Set ACADApp = GetObject(, "AutoCAD.Application")
End Sub
Private Sub ACADApp_EndOpen(ByVal FileName As String)
RunMacro "Module1.RunThis"
End Sub
Private Sub ACADApp_NewDrawing()
RunMacro "Module1.RunThis"
End Sub
in the ThisDocument code pane place this
Dim Aok As Class1
Private Sub AcadDocument_Activate()
If Aok Is Nothing Then Set Aok = New Class1
If IsEmpty(ACADApp) Then Aok.AcadApplication_Events
End Sub
Happy Coding :)
MikeS
03-31-2005, 10:56 AM
Thanks, works great! :thumb
Tommy
03-31-2005, 11:15 AM
Good Deal! Let me know if I can help some more :)
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.