Using the AddAdvise method to receive event notifications

  • Thread starter Christophe Carbognin
  • Start date
C

Christophe Carbognin

I use the the AddAdvise method in the procedure below (CreateEventObjects) to
add Event objects to the EventList collection of the source object whose
events I want to receive. When selected events occur, the source object
notifies my sink object (clsEventSink).

When I run CreateEventObjects I receive an error "An exception occured" on
the the following line:

'Add an Event object for the SelectionChanged event.
Set vsoSelectionChangedEvent = vsoDocumentEvents.AddAdvise( _
visEvtCodeWinSelChange, mEventSink, "", "Selection changed...")

I canno figure out why when I use the constant visEvtCodeWinSelChange that I
receive this error. If I just replace it with another constant, sometimes it
works depending on the code. It's as if some code are accepted and others not.

Has anyone encoutered this problem? Can anyone help? Thank you.


Sub CreateEventObjects()
'On Error GoTo ErrorHandler

'Create an instance of the clsEventSink class
'to pass to the AddAdvise method.
Set mEventSink = New clsEventSink

'Get the EventList collection of the active document.
Set vsoDocumentEvents = ActiveDocument.EventList

'Add Event objects that will send notifications.

'Add an Event object for the SelectionChanged event.
Set vsoSelectionChangedEvent = vsoDocumentEvents.AddAdvise( _
visEvtCodeWinSelChange, mEventSink, "", "Selection changed...")

'Add an Event object for the SelectionChanged event.
Set vsoSelectionChangedEvent = vsoDocumentEvents.AddAdvise( _
visEvtCodeWinSelChange, mEventSink, "", "Selection changed..."

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top