Click here to Skip to main content
11,795,568 members (79,570 online)
Rate this: bad
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 1:00am
2000 P574
Edited 22-Apr-11 2:31am
Ankit Rajput at 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 at 22-Apr-11 8:41am
no still objWord.Windows.Count is 0 :(
Ankit Rajput at 22-Apr-11 10:55am
You have Microsoft Word or anyother Company or any Open source word document
prasad.koila at 24-Apr-11 23:45pm
office 2007
Ankit Rajput at 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 at 25-Apr-11 3:00am
Closed all the word process and reexecuted then problem solved. Thank you Ankit.
prasad.koila at 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
0 Maciej Los 340
1 Sergey Alexandrovich Kryukov 316
2 OriginalGriff 285
3 Abhinav S 223
4 KrunalRohit 214
0 OriginalGriff 1,797
1 Maciej Los 1,415
2 KrunalRohit 1,240
3 CPallini 840
4 ppolymorphe 808

Advertise | Privacy | Mobile
Web02 | 2.8.151002.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