Windows Phone Developers

Showing posts with label C# GetObject Method. Show all posts
Showing posts with label C# GetObject Method. Show all posts

Wednesday, January 7, 2009

How to use Existing Instance of Excel in C#



C# GetObject Method

Marshal.GetActiveObject gets a running instance of the specified object from the Running Object Table (ROT).

using System.Runtime.InteropServices;

using Excel = Microsoft.Office.Interop.Excel;

private void GetExcel()

{

try

{

oXL = (Excel.Application)Marshal.GetActiveObject("Excel.Application");

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

}

Marshal.GetActiveObject exposes the GetActiveObject COM API method from OLEAUT32.DLL; however, the latter expects a class identifier (CLSID) instead of the programmatic identifier (ProgID) expected by this method. To obtain a running instance of a COM object without a registered ProgID, use platform invoke to define the GetActivateObject COM method


Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon