ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   ReferencesEvents (https://www.excelbanter.com/excel-programming/341703-referencesevents.html)

anonymousA

ReferencesEvents
 
Hi,

Does anybody know about using ReferencesEvents ?

I've tried using the sample from VBA Help but it doesn't work .I made a

class module and in a standard module I declare the variable.

My code below

in a class module named Class1

Public WithEvents X As VBIDE.ReferencesEvents
Private Sub Class_Initialize()

MsgBox "initialized"

End Sub
Private Sub Class_Terminate()

MsgBox "over"

End Sub
Private Sub X_ItemAdded(ByVal Reference As VBIDE.Reference)
MsgBox Reference.Name
End Sub
Private Sub X_ItemRemoved(ByVal Reference As VBIDE.Reference)
MsgBox "tata"
End Sub

In a standard module

Dim TT As New Class1
Sub ff()

Set TT.X =
Application.VBE.Events.ReferencesEvents(ThisWorkbo ok.VBProject)

End Sub

Every time I add or remove a reference, I should have the messages I
put
into the subs X_ItemAdded or X_ItemRemoved but I get neither of these.

Moreover, what it's really strange, when I add a reference, I get the
message of Sub Class_Initialize ( which is quite normal anyway
according
to the declarations I made ) but when I remove the same reference
immediately after , I get the message of Sub Class_Terminate which I
find odd to get , in that case.
I can't happen fixing the problem

Could anybody help please ?

Regards



All times are GMT +1. The time now is 09:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com