Click here to Skip to main content
15,891,811 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to get no of running instances of word/PPT applications if different versions of MS office running?
This code does not return all the insatnces if multiple versions documents opened.
Please help.

MIDL
//for powerpoint instance
ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
//for word instance
                        wordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
Posted
Comments
Chris Meech 28-Apr-11 8:40am    
Is it possible to have different versions of MS Office installed?
2000 P 28-Apr-11 9:02am    
yes.. I have installed 2003, 2007, 2010 versions

Managed to somewhat like this and it will return all the running process:
MIDL
Process[] wordProcs = Process.GetProcessesByName("WINWORD");
if (wordProcs.Length > 0)
{
   foreach (Process wordProc in wordProcs)
    {
      if (wordProc.MainWindowTitle != "")
        {
           //Do something here
        }
    }

}
 
Share this answer
 
Each version of the COM library will most likely have access to only those instances from the same version. So if you have 2 versions of Office, you'll probably need to COM interop with them separately.

[Update]
~~~~~~~~~~

In response to your comment:

Yeah you'll need separate assemblies that link to specific interop versions. And maybe a common assembly that can then act as the sync-ing point.
 
Share this answer
 
v3
Comments
2000 P 28-Apr-11 8:54am    
I have 2003, 2007, 2010 office version. For ex, if i open PPT one by one, program detects the instance. But when all three versions documents are open, it fails to get the instances. I am using Microsoft.Office.Core version 14.0 and 12.0 com interops.
Nish Nishant 28-Apr-11 9:00am    
Yeah you'll need separate assemblies that link to specific interop versions. And maybe a common assembly that can then act as the sync-ing point.
2000 P 29-Apr-11 0:49am    
Couldn't get your comment. this is wht I am doing :

Microsoft.Office.Interop.PowerPoint.Application ppApp;

ppApp = new Microsoft.Office.Interop.PowerPoint.Application();

int i = ppApp.Windows.Count;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900