Main Content


Unregister event handler associated with COM object event at run time



unregisterevent(c,eventhandler) removes the association of a specific event handler routine from its corresponding event. Once you unregister an event, the object no longer responds to the event. You can unregister events at any time after creating a control.


collapse all

Unregister the EvtDeactivateHndlr event handler from a Microsoft® Excel® workbooks Deactivate event.

To run this example, create a workbook and register events.

myApp = actxserver('Excel.Application');
wbs = myApp.Workbooks;
wb = Add(wbs);
registerevent(wb,{'Activate' 'EvtActivateHndlr'; 'Deactivate' 'EvtDeactivateHndlr'})
ans =

  2×2 cell array

    'Activate'      'EvtActivateHndlr'  
    'Deactivate'    'EvtDeactivateHndlr'

Unregister the Deactivate event handler. MATLAB® shows the remaining registered event (Activate) with its corresponding event handler.

unregisterevent(wb,{'Deactivate' 'EvtDeactivateHndlr'})
ans =

  1×2 cell array

    'Activate'    'EvtActivateHndlr'

Input Arguments

collapse all

COM object, specified as a function handle.

Function to call when event occurs, specified as a cell array, specifies both events and event handlers.

Specify events in the eventhandler argument using the names of the events. Strings or character vectors used in the eventhandler argument are not case-sensitive. unregisterevent does not accept numeric event identifiers.


  • COM functions are available on Microsoft Windows® systems only.

Version History

Introduced before R2006a