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
| Event | Description |
| BeforeAddDataBoundRow | Occurs 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. |
| BeforeDoubleClick | Occurs when the ListObject is double clicked |
| BeforeRightClick | Occurs when the ListObject is right clicked |
| BindingContextChanged | Occurs when the binding of the ListObject changes |
| Change | Occurs when the contents of the ListObject are changed by a user or programmatically. The event is not raised when calculations cause the change |
| DataBindingFailure | Occurs when the binding of the ListObject fails. This occurs when you try and add a second ListObject to a worksheet. |
| DataMemberChanged | Occurs when the DataMember property is changed by a user or programmatically. |
| DataSourceChanged | Occurs when the DataSource property is changed by a user or programmatically. |
| Deselected | Occurs when the selection is moved outside the ListObject. |
| ErrorAddDataBoundRow | Occurs when an error occurs when attempting to add a new row, (eg violation, entering text in a numeric column) |
| OriginalDataRestored | Occurs when a changed value is restored to its original value as a consequence of an error occurring. |
| Disposed | Occurs when the ListObject is disposed of. Typically raised by garbage collection. |
| Selected | Occurs when the ListObject is selected |
| SelectedIndexChanged | Occurs when the selected index changes. This is the currently selected item in the ListObject. |
| SelectionChange | Occurs 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
| Event | Description |
| BeforeDoubleClick | Occurs when the namedrange control is double clicked. This occurs before the double click. |
| BeforeRightClick | Occurs when a namedrange control is right clicked |
| BindingContextChanged | Occurs when the binding of the Named Range changes |
| Change | Occurs when something changes inside the named range control |
| Deselected | Occurs when the selection is moved outside the Named Range |
| Disposed | Occurs when the Named Range is disposed of. Typically raised by garbage collection. |
| Selected | Occurs when the namedrange control is selected |
| SelectionChange | Occurs 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
| Event | Description |
| BeforeDoubleClick | Occurs when the XMLMappingRange is double clicked |
| BeforeRightClick | Occurs when the XMLMappingRange is right clicked |
| BindingContextChanged | Occurs when the binding of the XMLMappingRange changes |
| Change | Occurs when the contents of the XMLMappingRange are changed by ?? |
| Deselected | Occurs when the selection is moved outside the XMLMappingRange |
| Disposed | Occurs when the XMLMappingRange is disposed of. Typically raised by garbage collection. |
| Selected | Occurs when the XMLMappingRange is selected |
| SelectionChange | Occurs 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