Consulting

Results 1 to 4 of 4

Thread: AutoCAD 2007 - Run routine when opening dwg

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    11
    Location

    AutoCAD 2007 - Run routine when opening dwg

    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:
    [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]

    in the Class Modules tab:
    [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 "AddaBlock.XrefUpdate"
    End Sub

    [/vba]

    and in the modules tab..

    [vba]
    Sub XrefUpdate()
    ..code...
    End Sub
    [/vba]

    TIA for any help

  2. #2
    VBAX Regular fixo's Avatar
    Joined
    Jul 2006
    Location
    Sankt-Petersburg
    Posts
    99
    Location
    Just an idea only because I have not have A2007

    Change this line:

    [vba]Set ACADApp = GetObject(, "AutoCAD.Application")[/vba]

    on

    [vba]
    Set ACADApp = GetObject(, "AutoCAD.Application.17")
    [/vba]

    HTH

    Fatty

    ~'J'~

  3. #3
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,168
    Location
    here is to hoping the module name is "AddaBlock".

    Where is the error?
    What does it say?

  4. #4
    VBAX Regular
    Joined
    Mar 2005
    Posts
    11
    Location
    The error has been resolved. Apparently VBA and/or AutoCAD doesn't like when you have 2000 and 2007 running at the same time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •