why this event no work?

why this event no work?

Anonymous
Not applicable
191 Views
1 Reply
Message 1 of 2

why this event no work?

Anonymous
Not applicable
in the thisdrawing module a2ki

Option Explicit

Public WithEvents AcadApp As AcadApplication
Public WithEvents AcadDoc As AcadDocument

Sub acaddoc_activate()
Set AcadApp = Application
Set AcadDoc = AcadApp.ActiveDocument
MsgBox AcadApp.ActiveDocument.Name
End Sub

Sub acadapp_appactivate()
Set AcadApp = Application

Debug.Print AcadApp.ActiveDocument.Name
MsgBox AcadApp.ActiveDocument.Name

End Sub

I thought, foolishly that this would report every time I change document,
but it only fires when entering and leaving the one in which the sub was
begun, except for once when it fired after changing a doc and then changing
app. but usually it only reports "Drawing1", even though I'm switching
between "Drawing1" and "whatever".
after a few test runs with this and variations thereof memory gets bunged up
and acad crashes.

still mystified at events
Mark
0 Likes
192 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
it seems this works

Sub acadapp_appactivate()
Set AcadApp = Application
Set AcadDoc = AcadApp.ActiveDocument
MsgBox AcadDoc.Name

End Sub
'when swithching to or from acad msgbox fires

'and this works
Private Sub AcadApp_EndOpen(ByVal FileName As String)
MsgBox FileName
End Sub
'upon opening dwg msgbox fires

'but this doesn't work except in the first dwg the sub is run in
'if there are four dwgs open and I flip through them with ctl tab it fires
when I get to drawing1 but not on the other three

Sub acaddoc_activate()
Set AcadApp = Application
Set AcadDoc = AcadApp.ActiveDocument
MsgBox AcadDoc.Name, vbCritical, "Acad Doc Activate"

End Sub

I thought that each time a doc was activated, this would fire since acadapp
is with events and acaddoc also,
obviously it's not that easy!?!

Do I have to put all dwgs in a collection and create a separate class and
set each dwg in turn to be an instance of that class? Then how do I write
it in the class to report it's name? in the Class_Initialize sub? but
thatwould only run the first time the reference is made wouldn't it? Or do
I destroy each instance when another dwg becomes active? so that every time
the active document changes an object is destroyed and another created?

It seems like this should be really easy to do, but...

lookin for ideas
mp
0 Likes