M
mp
I want to get a reference to a running instance of excel
currently i'm using _xlApp = new Excel.Application();
but obviously that's not what i want
found two answers so far
1 add a reference to the .NET Component "Microsoft.VisualBasic".
and use Microsoft.VisualBasic.Interaction.GetObject()
but that sounded nasty...so i keep searching...
2 System.Runtime.InteropServices.Marshal.GetActiveObject
that sounds better(no vb) so i tried
....
at top of class
private Excel.Application _xlApp;
....
then in method i tried:
_xlApp
=System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
and got this error:
//Cannot implicitly convert type 'object' to 'Excel.Application'.
//An explicit conversion exists (are you missing a cast?)
so i tried
_xlApp
=(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
and got the same error
I thought (typeToCastTo)objectToCast was the way to cast in c#????
what's the solution?
thanks
mark
currently i'm using _xlApp = new Excel.Application();
but obviously that's not what i want
found two answers so far
1 add a reference to the .NET Component "Microsoft.VisualBasic".
and use Microsoft.VisualBasic.Interaction.GetObject()
but that sounded nasty...so i keep searching...
2 System.Runtime.InteropServices.Marshal.GetActiveObject
that sounds better(no vb) so i tried
....
at top of class
private Excel.Application _xlApp;
....
then in method i tried:
_xlApp
=System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
and got this error:
//Cannot implicitly convert type 'object' to 'Excel.Application'.
//An explicit conversion exists (are you missing a cast?)
so i tried
_xlApp
=(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
and got the same error
I thought (typeToCastTo)objectToCast was the way to cast in c#????
what's the solution?
thanks
mark