This project has moved and is read-only. For the latest updates, please go here.

Excel ActiveWorkbook null

Jan 19, 2015 at 8:03 PM
I am trying to read the current Workbook in Excel.

I call:

Excel.Application excelApplication = Excel.Application.GetActiveInstance();
Excel.Workbook currentWorkBook = excelApplication.ActiveWorkbook;

currentWorkBook is null after these calls, even though I can physically see that a workbook is open in excel.

Do I need to make some call beforehand? Is this a known issue? Any information would help.

Jan 21, 2015 at 2:00 PM
GetActiveInstance() gives you the first instance in memory. may you have multiple instances in memory.

foreach(var item in Excel.Application.GetActiveInstances())
Console.WriteLine("Book: {0}", item.ActiveWorkbook);

(BTW: GetActiveInstances in NO 1.7.2 level a microsoft issue in the COM Running Object Table. make sure to use NO 1.7.2 or higher)