I am writing an Excel Add-in. Following is my code
private void ThisAddInStartup(object sender, EventArgs e)
{
Excel.Sheets sheets = Application.ActiveWorkbook.Sheets;
_worksheet = (from Excel.Worksheet sheet in sheets where sheet.Name.Contains(SheetName) select sheet).FirstOrDefault();
Application.SheetChange += ApplicationSheetChange;
}
When I debug, everything works great. But When I open an excel file directly from my hard drive then I am getting Application.ActiveWorkbook
as null
. Can anybody help me to understand this.
I want to start my add-in as when an excel file opens. Basically my add-in is tracking change in excel sheet of workbook and doing some required action.
If it matters, I am using Office 2007, Visual Studio 2012. I am able to run the solution after changing the project file and replacing Office 14
part with 12
.