Before you can use document level events in VB or another environment besides VBA, you must create a new class module and declare an object of type AcadDocument with events. For example, assume a new class module is created and called EventClassModule. The new class module contains the declaration of the application with the VBA keyword WithEvents.
Public WithEvents Doc As AcadDocument
After the new object has been declared with events, it appears in the Object drop-down list box in the class module, and you can write event procedures for the new object in the class module. (When you select the new object in the Object box, the valid events for that object are listed in the Procedure drop-down list box.)
Before the procedures will run, however, you must connect the declared object in the class module with the Document object. You can do this with the following code from any module.
Dim X As New EventClassModule
Set X.Doc = ThisDrawing
Once the InitializeEvents procedure has been run, the Doc object in the class module points to the Document object created, and any event procedures in the class module will run when the events occur.