get current Instance of Word

J

Jazper Manto

hi

i want to open a document in word by my app. therefore i wrote some code.

Type tWordApp = Type.GetTypeFromProgID("Word.Application");
Word.ApplicationClass oWordApp = (Word.ApplicationClass)
Activator.CreateInstance(tWordApp);

the probem is that i get a complete new instance even when the user already
opend the word before starting my application. so i'm looking for a solution
to check fist if there are currently any instances of the word application.
does anybody know how to do that?
thank you! jazper m.
 
A

Andreas Håkansson

Jazper,

I believe that the office applications register themselfs with the ROT
(Running Objects Table)
and you possibly could retreive it from there. Luckly there is a static
method on the Marshal
class to do this

Marshal.GetActiveObject()

Pass it the prodid of the object you want to fetch and go nuts =) You could
also start digging
through the ROT with the UCOMIRunningObjectTable.EnumRunning method.

HTH,

//Andreas
 
J

Jazper Manto

Did you try Activator.GetObject() method ?
no. because i did not find a method like that by intelisense...
however i'll try it too...
jazper
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top