This project has moved. For the latest updates, please go here.

How to get the running word/excel application object?

Jun 14, 2011 at 2:34 PM
Edited Jun 14, 2011 at 2:35 PM

It seems that the examples for word/excel always create a new application object.

How to get the running application object?

Coordinator
Jun 15, 2011 at 6:43 PM
Edited Jun 15, 2011 at 6:43 PM

excel holds open workbooks in running object table.
word holds application and open documents in running object table.
Examples\Misc\GetRunningOutloukInstance.sln demonstrate to accsessing a runnng object from ROT(running object table)
i do examples for other office applications very soon.
create an issue if you want.

best wishes
sebastian



.

Jul 6, 2011 at 10:30 AM

You need to be careful when using the Application reference from the ROT, particularly when you are running as an add-in inside the office application. The instance registered in the ROT will refer to the last instance of the application that was started, which might differ from the instance you are actually running in.

The right way to get the Application instance from within your add-in (if you didn't store the instance in Connect) is to get a window handle for your instance, then call AccessibleObjectFromWindow(..). There is some useful discussion here: http://blogs.officezealot.com/whitechapel/archive/2005/04/10/4514.aspx and here: http://blogs.msdn.com/b/andreww/archive/2008/11/30/starting-or-connecting-to-office-apps.aspx.

-Govert

Excel-DNA - Free and easy .NET for Excel

Coordinator
Jul 6, 2011 at 11:04 AM
Edited Jul 6, 2011 at 11:05 AM

 partially right, different office applications do different things. for example outlook can be started one time and its easy to get application object from ROT.
excel stores all open workbooks to ROT and not the application object but you can get the application object from the worbook proxy.
anyway, a COMAddin has to use the Connect function from IDTExtensiblity2 of course to get the application proxy.
*best regards