[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

GetActiveObject is returning System.__ComObject

SteveB

6/16/2008 6:30:00 PM

hello group:
i am using the following C# statement to acquire the Excel instance
currently running:

Excel.Application app =
(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
--

but, the value of app is System.__ComObject.
why isn't it Excel.Workbook or Excel.Application?

note, i have Excel running and a workbook is opened.

thanks in advance...
LakeFront.
2 Answers

Jeroen Mostert

6/16/2008 8:32:00 PM

0

Lakefront wrote:
> hello group:
> i am using the following C# statement to acquire the Excel instance
> currently running:
>
> Excel.Application app =
> (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
>
> --
>
> but, the value of app is System.__ComObject.
> why isn't it Excel.Workbook or Excel.Application?
>
Because you're actually getting a COM wrapper rather than an instance of any
particular class.

Use interfaces rather than classes: casting to IApplication should work.

--
J.
http://symbolsprose.bl...

SteveB

6/17/2008 9:06:00 PM

0

problem solved!



Lakefront wrote:
> hello group:
> i am using the following C# statement to acquire the Excel instance
> currently running:
>
> Excel.Application app =
> (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
>
> --
>
> but, the value of app is System.__ComObject.
> why isn't it Excel.Workbook or Excel.Application?
>
> note, i have Excel running and a workbook is opened.
>
> thanks in advance...
> LakeFront.