Application

For a full list of all the application level events refer to the Excel > Events > Application Level page.


void WhichObject (string eventName, object sheet) 
{
   Excel.Worksheet wsh = sheet as Excel.Worksheet
   if (worksheet != null)
   {
      // this is a worksheet
   }
   Excel.Chart cht = sheet as Excel.Chart
   {
      // this is a chart
   }
}

In VSTO you do not have to keep a reference to the workbook, worksheet or chart objects when handling events because they are already being kept by the project items generated by the project.
However you do need to keep a reference to the Application object
To get a worksheet or chart we can use the VSTO's Global object


AfterCalculate



WorkbookBeforeClose

This creates an event handler for the WorkbookBeforeClose application level event.

public void Event_Application_WorkbookBeforeClose(Excel.Workbook workbook, ref bool Cancel) 
{
}
gApplicationExcel.WorkbookBeforeClose += Event_Application_WorkbookBeforeClose;

'VB.Net Equivalent
Addhandler gApplicationExcel.WorkbookBeforeClose _
   AddressOf Event_Application_WorkbookBeforeClose

WorkbookDeactivate

This creates an event handler for the WorkbookDeactivate application level event.

public void Event_Application_WorkbookDeactivate(Excel.Workbook workbook) 
{
}
gApplicationExcel.WorkbookDeactivate += Event_Application_WorkbookDeactivate;

'VB.Net Equivalent
Addhandler gApplicationExcel.WorkbookDeactivate _
   AddressOf Event_Application_WorkbookDeactivate

WorkbookOpen

This creates an event handler for the WorkbookOpen application level event.

public void Event_Application_WorkbookOpen(Excel.Workbook workbook) 
{
}
gApplicationExcel.WorkbookOpen += Event_Application_WorkbookOpen;

'VB.Net Equivalent
Addhandler gApplicationExcel.WorkbookOpen _
   AddressOf Event_Application_WorkbookOpen

NewWorkbook

NewWorkbook is the name of both a property and an event.

public void Event_Application_NewWorkbook(Excel.Workbook workbook) 
{
}
((Excel.AppEvents_Event)gApplicationExcel).NewWorkbook +=
   new Excel.AppEvents_NewWorkbookEventHandler(Event_Application_NewWorkbook);

'VB.Net Equivalent
Addhandler CType(gApplicationExcel, Excel.AppEvents_Event).NewWorkbook _
   AddressOf Event_Application_NewWorkbook


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