1

Do you know how to get applications IDs ("Word.Application" in given example)? What if I will need Excel? Or InDesing?

object word;
try
{
    word = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
//If there is a running Word instance, it gets saved into the word variable
}
catch (COMException)
{
//If there is no running instance, it creates a new one
    Type type = Type.GetTypeFromProgID("Word.Application");
    word = System.Activator.CreateInstance(type);
}

Find existing instance of Office Application

Community
  • 1
  • 1
  • 1
    What you mean by *application ID* BTW? – Rahul Oct 12 '15 at 07:35
  • Where are you starting from? That is: what information do you have from which you want to obtain the name? (PS. "Application Id" already has a meaning in COM: and it is another usage of GUID, these names are normally known as a "program ids, or more commonly *progid*. – Richard Oct 12 '15 at 07:38

1 Answers1

1

You can find this information out with Microsoft's OLE/COM Object Viewer.

You can use the OLE/COM Object Viewer to view a control's interfaces. Tell me more...

e.g. going by the Word example, first expand the All Objects node:

enter image description here

...then scroll down to Microsoft Word Application. The version independent ProgID will be shown on the right. Use that in your application.

enter image description here

What if I will need Excel?

As before, scroll until you find Microsoft Excel Application.

enter image description here

Here we can see it is Excel.Application. If you have multiple versions installed and wish to use a specific version, use the ProgId as shown in the ProgID field.


Note: If like me you encounter multiple entries, take the one that shows either a ProgID or VersionIndependentProgID.