I'm having trouble connecting my Workbook_SheetChange Event Handler to an active workbook. I've tried several methods to no avail, it just keeps saying my workbook or instance of Excel (xlApp) is null and throws the exception.
Here's the code:
private void createProject_Click(object sender, RibbonControlEventArgs e)
{
Excel.Application xlApp;
xlApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
exwb = (Excel.Workbook)xlApp.ActiveWorkbook;
MessageBox.Show(exwb.Name);
EventDel_CellsChange = new Excel.WorkbookEvents_SheetChangeEventHandler(narrator.Workbook_SheetChange);
xlApp.ActiveWorkbook.SheetChange += EventDel_CellsChange;
}
The problem is the last line and please note I've substituted xlApp.ActiveWorkbook for exwb multiple times