Click here to Skip to main content
11,494,851 members (71,190 online)
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 Dnyaneshwar@Pune 692
1 Sergey Alexandrovich Kryukov 354
2 CHill60 293
3 Sascha Lefèvre 255
4 Nakul Chaudhari 236
0 Sergey Alexandrovich Kryukov 10,297
1 OriginalGriff 8,821
2 Sascha Lefèvre 3,864
3 Maciej Los 3,412
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 12 May 2011
Copyright © CodeProject, 1999-2015
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