Tommy,
What you should do from Excel is pass the name of the workbook to your
process. With that, you should be able to pass that to the
CreateFileMoniker function through the P/Invoke layer. This will give you
an IMoniker interface (use the definition from the
System.Runtime.InteropServices.ComTypes namespace for the IMoniker
definition) which you can then pass to the GetObject method on the
IRunningObjectTable interface. You get the IRunningObjectTable interface by
calling the GetRunningObjectTable function through the P/Invoke layer.
You would pass the path of the workbook to the GetObject method, and you
should be able to cast what you get back into something usable (either the
workbook instance, or the application instance).
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
<re***@nrcan.gc.cawrote in message
news:11**********************@o38g2000hse.googlegr oups.com...
>I have an Excel workbook that launch an external .exe. My .exe is
written in c#. My application need a reference to the excel
applicationthat just call it. When calling the external .exe (my c#
application) from Excel, i'm passing the Excel PID in arguments. In c#
i'm able to get the Excel process with Process.GetProcessById(pid) but
i don't know how to cast it back to an Excel application Object. ex :
appExcel = (Excel.Application)(Process.GetProcessById(pid)) this
doesn't work.
I need something like that but with the process pid :
appExcel =
(Excel.Application)Marshal.GetActiveObject("Excel. Application");
Thanks,
Tommy