Event Handling

To handle the events you need to do two things:
1) Declare a handler method with the required signature

public void Application_SheetActivate(object sh) 
{
}

2) Connect your handler method to the Excel object model that raises this event

this.Application.SheetActivate += 
    new Excel.AppEvents_SheetActivateEventHandler(Application_SheetActivate)

Visual Studio displays a popup tooltip and will actually generate most of this line for you.
As soon as you type "+" a popup tooltip will be displayed
If you press Tab key twice Visual Studio generates the rest of the line and the event handler for you automatically


You can also use the Properties window to add event handlers
Double click the workbook class
Click on the lightning bolt icon to show events associated with this object


A lot of the events in the Excel object model are repeated on the Application, Workbook and Worksheet objects
For a complete list of all the events, please refer to Excel > Macros > Events


Events and Methods with the same name

There are several cases when an object has both an event and a method with the same name
To handle these events you must cast your object to the interface that contains the corresponding event definition


Here is an example of how to declare an event handler for the Workbook level NewSheet event

public void Event_WorkbookNewWorksheet(object sheet) 
{
}

gApplicationExcel.ActiveWorkbook.NewSheet +=
   new Excel.WorkbookEvents_NewSheetEventHandler(Event_WorkbookNewWorksheet);

However there are a few events which have ambiguous names.
In these situations you must cast the object to the corresponding interface first.
Application object must be cast to AppEvents_Event.
Workbook object must be cast to WorkbookEvents_Event.
Worksheet object must be cast to DocEvents_Event.
Chart object must be cast to ChartEvents_Event.
You can avoid these ambiguous interfaces in VB.Net if you use WithEvents and Handles rather than using the AddHandler.


Workbook_Activate

Activate is the name of both a method and an event.

public void Event_WorkbookActivate() 
{
}

((Excel.WorkbookEvents_Event)gApplicationExcel.ActiveWorkbook).Activate +=
    new Excel.WorkbookEvents_ActivateEventHandler(Event_WorkbookActivate);

Addhandler CType(gApplicationExcel.ActiveWorkbook, Excel.WorkbookEvents_Event).Activate 
Public Sub Event_ApplicationNewWorkbook(ByVal workbook As Excel.Workbook)
End Sub

If you want to fire this event manually you can use the following code:

objworkbook = gApplicationExcel.Workbooks("WbkName") 
CType(objworkbook, Excel._Workbook).Activate()

Worksheet - ListObject

EventDescription
BeforeAddDataBoundRowOccurs when a user attempts to add a new row. This event is not raised when new rows are added programmatically. Useful when validating the data.
BeforeDoubleClickOccurs when the ListObject is double clicked
BeforeRightClickOccurs when the ListObject is right clicked
BindingContextChangedOccurs when the binding of the ListObject changes
ChangeOccurs when the contents of the ListObject are changed by a user or programmatically. The event is not raised when calculations cause the change
DataBindingFailureOccurs when the binding of the ListObject fails. This occurs when you try and add a second ListObject to a worksheet.
DataMemberChangedOccurs when the DataMember property is changed by a user or programmatically.
DataSourceChangedOccurs when the DataSource property is changed by a user or programmatically.
DeselectedOccurs when the selection is moved outside the ListObject.
ErrorAddDataBoundRowOccurs when an error occurs when attempting to add a new row, (eg violation, entering text in a numeric column)
OriginalDataRestoredOccurs when a changed value is restored to its original value as a consequence of an error occurring.
DisposedOccurs when the ListObject is disposed of. Typically raised by garbage collection.
SelectedOccurs when the ListObject is selected
SelectedIndexChangedOccurs when the selected index changes. This is the currently selected item in the ListObject.
SelectionChangeOccurs when the selection within the ListObject changes.

This list is slightly different to the VBA Events


You can create ListObjects dynamically


Microsoft.Office.Tools.Excel.ListObject AddListObject( 
   Microsoft.Office.Interop.Excel.Range range,
   string name)

Public Function AddListObject( _ 
   ByVal range As Microsoft.Office.Interop.Excel.Range, _
   ByVal name As String) As _
   Microsoft.Office.Tools.Excel.ListObject


Excel.Worksheet vstosheet; 
Microsoft.Office.Tools.Excel.ListObject listobject;
vstosheet = ActiveWorkbook.Sheets(2).GetVSTOObject
listobject = vstosheet.Controls.AddListObject(Range("A1","B10"),
                     new System.Guid(---).ToString())

Worksheet - NamedRange

EventDescription
BeforeDoubleClickOccurs when the namedrange control is double clicked. This occurs before the double click.
BeforeRightClickOccurs when a namedrange control is right clicked
BindingContextChangedOccurs when the binding of the Named Range changes
ChangeOccurs when something changes inside the named range control
DeselectedOccurs when the selection is moved outside the Named Range
DisposedOccurs when the Named Range is disposed of. Typically raised by garbage collection.
SelectedOccurs when the namedrange control is selected
SelectionChangeOccurs when the selection moves inside the namedrange control

This list is slightly different to the VBA Events


You can create NamedRanges dynamically.


Microsoft.Office.Tools.Excel.NamedRange AddNamedRange( 
   Microsoft.Office,Interop.Excel.Range range,
   string name)

Public Function AddNamedRange( _ 
   ByVal range As Microsoft.Office.Interop.Excel.Range. _
   ByVal named As String) As _
   Microsoft.Office.Tools.Excel.NamedRange

Worksheet - XMLMappedRange

EventDescription
BeforeDoubleClickOccurs when the XMLMappingRange is double clicked
BeforeRightClickOccurs when the XMLMappingRange is right clicked
BindingContextChangedOccurs when the binding of the XMLMappingRange changes
ChangeOccurs when the contents of the XMLMappingRange are changed by ??
DeselectedOccurs when the selection is moved outside the XMLMappingRange
DisposedOccurs when the XMLMappingRange is disposed of. Typically raised by garbage collection.
SelectedOccurs when the XMLMappingRange is selected
SelectionChangeOccurs when the selection within the XMLMappingRange changes.

This list is slightly different to the VBA Events
These cannot be created dynamically at run-time


Worksheet - OLEObject



© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext