Reputation: 789
I'm wondering if some other software create Excel instance, is it possible from c# to access that instance and close but without killing the process ?
I had tried with Marshal.GetActiveObject("Excel.Application")
but that is throwing me the error:
System.Runtime.InteropServices.COMException: 'Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))'
Upvotes: 0
Views: 251
Reputation: 789
I found a way to make it work. I had used
using Excel = Microsoft.Office.Interop.Excel.Application;
later in code I used:
var app = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
And this had created me a problem. I changed the code to:
using Microsoft.Office.Interop.Excel.Application;
and
var obj = (Microsoft.Office.Interop.Excel.Application)Marshal.GetActiveObject("Excel.Application");
obj.Quit();
And now this is working normally.
Upvotes: 1