Get an Excel.Application object from a process or hwnd in .NET.

In C #, I'm trying to get an instance of an Excel.Application object from a Process object. It seems to be really simple, but I can't figure it out and can't find an example. To repeat, I have a System.Diagnostics.Process object that I know relates to an executable instance of Excel. Now I need to restore the Microsoft.Office.Interop.Excel.Application object, which refers to the process so that I can manipulate the Excel application with C #.

In case this simplifies, I also have an HWND identifier and window text associated with the active Excel window.

Thank.

+5
source share
3 answers

Answered by another SO post:

Excel CLSID Excel ?

+2

Visual # Office

using Excel = Microsoft.Office.Interop.Excel;
:    

private void button1_Click(object sender, System.EventArgs e)
{

    //Excel Application Object
    Excel.Application oExcelApp;

    this.Activate();

    //Get reference to Excel.Application from the ROT.
    oExcelApp =  (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");

    //Display the name of the object.
    MessageBox.Show(oExcelApp.ActiveWorkbook.Name);

    //Release the reference.
    oExcelApp = null;
}

, Process? , .

+2

, Excel, Hwnd, ProcessID Process.

http://www.codeproject.com/Tips/1080611/Get-a-Collection-of-All-Running-Excel-Instances

- API Win32, .

Excel Windows.

+1

All Articles