473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Excel PID process casting

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

Nov 2 '07 #1
1 6427
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

Nov 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sri | last post by:
I am writing an asp.net applicaition using VB coding. In a function, I am opening an excel file with the following code, Dim objExcel As Object Dim objWorkBook As Object objExcel =...
10
by: Lars-Erik Aabech | last post by:
Hi! This issue have been discussed a lot, but I haven't found a solution that applies to ASP.NET. I have a library which does some operations on Excel documents, and it will be used in an...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
2
by: Powerguy | last post by:
Hi all, I am looking for a way to get the Process id (or a handle) of an EXCEL process created from within my code. For example when the following code is executed: Dim EXL As...
18
by: lgbjr | last post by:
Hi All, I have a VB.NET app that, among other things, writes data to Excel. I am having trouble getting the Excel process to terminate after I quit Excel. I found an article related to this...
16
by: LP | last post by:
Hello, I am trying to use .NET with Excel. I installed Office 2003 and selected ..NET programming suport option, so it installed all those PIA, as MS sugests. But I can not find a way to destroy...
5
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the same...
1
by: fakehitswizard | last post by:
this is the correct way to close excel with C#. I've seen alot of other bogus posts ALL over the web that don't work, how frustrating. string savepath; bool foundPID; int ourPID = 0; int...
7
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.