I'm trying to get a hold of the excel application that is open. I'm using the Marshal.GetActiveObject("Excel.Application")
method to do this. I open the excel workbook manually and then try and get a hold of it. There is only one instance of excel open so I'm not sure why I'm getting a COMException
saying Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
My code is as follows
Microsoft.Office.Interop.Excel.Application oExcelApp=null;
oExcelApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application") as Excel.Application;
Craig
I use:
Microsoft.Office.Interop.Excel.Application oExcelApp = null;
try
{
oExcelapp = (Microsoft.Office.Interop.Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
}
catch {} // can do intelligent stuff here
if (oExcelApp == null)
{ Console.WriteLine("Excel not found"); }
else
{Console.WriteLine(oExcelApp.ActiveWorkbook.FullName);}
User contributions licensed under CC BY-SA 3.0