Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET Word
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.
 
//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 28-Apr-11 3:29am
2000 P569
Comments
Chris Meech at 28-Apr-11 8:40am
   
Is it possible to have different versions of MS Office installed?
prasad.koila at 28-Apr-11 9:02am
   
yes.. I have installed 2003, 2007, 2010 versions
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v3
Comments
prasad.koila at 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.
Nishant Sivakumar at 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.
prasad.koila at 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;
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 OriginalGriff 325
1 DamithSL 300
2 Sergey Alexandrovich Kryukov 289
3 CPallini 235
4 Maciej Los 215
0 OriginalGriff 5,455
1 DamithSL 4,422
2 Maciej Los 3,860
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,010


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 12 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100