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???
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???
Hi MikeS,
Welcome to VBAexpress!
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
[VBA]
Sub RunThis()
'place code you want to run here
End Sub
[/VBA]
in a class called Class1
[VBA]
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
[/VBA]
in the ThisDocument code pane place this
[VBA]
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
[/VBA]
Happy Coding
Thanks, works great!
Good Deal! Let me know if I can help some more