View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
anonymousA anonymousA is offline
external usenet poster
 
Posts: 32
Default 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