Click here to Skip to main content
11,922,641 members (57,289 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Word
Could some one help me for this problem?
//My requirement is : Inserting external objects in to the word and PPT document using C#. Inserting Menu should show all opened word and PPT documents. Here I am not able to get word's instance/document name.
For PPT we can use
ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
to get doucument name.
But how it is for MSWord? Below is the code which I tried.

Microsoft.Office.Interop.Word.Application wordApp;
wordApp = new Microsoft.Office.Interop.Word.Application();
MenuItem mn1;
int iTotInstance = wordApp.Windows.Count;
for (int insatnce = 1; insatnce <= wordApp.Windows.Count; insatnce++)
                               mn1 = new MenuItem(wordApp.Windows[insatnce].Name);
                               mn1.Index = iWord;
                               cm.MenuItems.Add(0, mn0);
Posted 22-Apr-11 2:00am
2000 P574
Edited 22-Apr-11 3:31am
Ankit Rajput 22-Apr-11 8:35am
Please check the new solution.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2


Please check it

Microsoft.Office.Interop.Word.Application objWord;
objWord= (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
for (int i = 0; i < objWord.Windows.Count; i++)
     object a = i+1;
     Window objWin = objWord.Windows.get_Item(ref a);

prasad.koila 22-Apr-11 8:41am
no still objWord.Windows.Count is 0 :(
Ankit Rajput 22-Apr-11 10:55am
You have Microsoft Word or anyother Company or any Open source word document
prasad.koila 24-Apr-11 23:45pm
office 2007
Ankit Rajput 25-Apr-11 2:23am
I have tested it with 2007 only and it is working fine at my end.
Is there any exception you are getting?
prasad.koila 25-Apr-11 3:00am
Closed all the word process and reexecuted then problem solved. Thank you Ankit.
prasad.koila 28-Apr-11 7:18am
Hi Ankit,

Here i am facing another problem. When I open different version of the (2003, 2007, 2010) word document simultaneously, program is able to detects only one document instance instead of 3. How can solve this problem?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151125.1 | Last Updated 22 Apr 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