In order to be able to refer to the Excel object model as "Excel", then you can create an alias via a using
statement at the top of your namespace (or document) as follows:
using Excel = Microsoft.Office.Interop.Excel;
Thereafter, you can refer to Excel.Application
instead of the long-winded Microsoft.Office.Interop.Excel.Application
.
As for why your call to Marshal.GetActiveObject is failing, I can't say for sure. A couple of thoughts:
(1) Are you certain that there is a running instance of Excel already present? If not, then create a new Excel application:
Excel.Application xlApp = new Excel.Application();
(2) If there definitely is an Excel application already running, then it is possible that the Excel instance has not yet been added to the Running Objects Table (ROT) if the Excel Application has never lost focus. See: Visual C# .NET Error Attaching to Running Instance of Office Application for more on this. I believe that the Marshal.GetActiveObject method should throw an exception in this case -- not quietly return null -- but this still seems potentially relevant.
I hope this helps...
Mike