To Connect the Declared Object to the Automation Object (VBA/ActiveX

Before the procedures will run, however, you must connect the declared object in the class module with the Circle object.

  1. In the Code window for your main module, add the following line to the declarations section:
    Dim X As New EventClassModule
  2. In the same window, create a circle called “MyCircle” and initialize it as containing events:
    Sub InitializeEvents()
     Dim MyCircle As AcadCircle
     Dim centerPoint(0 To 2) As Double
     Dim radius As Double
     centerPoint(0) = 0#: centerPoint(1) = 0#: centerPoint(2) = 0#
     radius = 5#
     Set MyCircle = ThisDrawing.ModelSpace.AddCircle(centerPoint, radius)
     Set X.Object = MyCircle
    End Sub
  3. In the code for your main module, add a call to the InitializeApp subroutine:
    Call InitializeEvents

    Once the InitializeEvents procedure has been run, the Circle object in the class module points to the Circle object created, and any event procedures in the class module will run when the events occur.

    Note: When coding in VBA, you must provide an event handler for all objects enabled for the Modified event. If you do not provide a handler, VBA may terminate unexpectedly.