Taking control of an existing instance of Excel

  • Thread starter Thread starter Adine
  • Start date Start date
A

Adine

User has opened an excel file and I want to take the control of the file. In
VB6 was not hard. Just I needed to use "GetObject" then I could select the
workbook. But now I don't know how to do it in C#.

Thanks
 
Adine,

You will want to use the static GetActiveObject method on the Marshal
class to do this.

Hope this helps.
 
I used:

excelObj =
(Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");

but did not work. I have opened 2 excel files but excelObj.Workbooks.Count
shows zero!

Nicholas Paldino said:
Adine,

You will want to use the static GetActiveObject method on the Marshal
class to do this.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Adine said:
User has opened an excel file and I want to take the control of the file.
In VB6 was not hard. Just I needed to use "GetObject" then I could select
the workbook. But now I don't know how to do it in C#.

Thanks
 
Back
Top