PDA

View Full Version : AutoCAD 2007 - Run routine when opening dwg



MikeS
12-05-2006, 10:08 AM
Simply put, I want to have AutoCAD run a vba routine whenever a drawing is openned.

Thanks to some help from this site, I have a routine that works for CAD 2000, but I am getting error messages in 2007.

Here is the code I have that works in 2000:

In the ThisDrawing tab:

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


in the Class Modules tab:

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 "AddaBlock.XrefUpdate"
End Sub



and in the modules tab..


Sub XrefUpdate()
..code...
End Sub


TIA for any help

fixo
12-06-2006, 12:07 PM
Just an idea only because I have not have A2007

Change this line:

Set ACADApp = GetObject(, "AutoCAD.Application")

on


Set ACADApp = GetObject(, "AutoCAD.Application.17")


HTH

Fatty

~'J'~

Tommy
12-13-2006, 02:54 PM
here is to hoping the module name is "AddaBlock".

Where is the error?
What does it say?

MikeS
12-14-2006, 09:05 AM
The error has been resolved. Apparently VBA and/or AutoCAD doesn't like when you have 2000 and 2007 running at the same time.