Click here to Skip to main content
15,890,399 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Could some one help me for this problem?
Thanks!
//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();
ppApp.Windows[i].Presentation.Name
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;
                               mn0.MenuItems.Add(mn1);
                               cm.MenuItems.Add(0, mn0);
                           }
Posted
Updated 22-Apr-11 2:31am
v3
Comments
Ankit Rajput 22-Apr-11 8:35am    
Please check the new solution.

1 solution

Hi,

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);
     MessageBox.Show(objWin.Caption);
}
objWin=null;


regards
Ankit
 
Share this answer
 
v2
Comments
2000 P 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
2000 P 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?
2000 P 25-Apr-11 3:00am    
Closed all the word process and reexecuted then problem solved. Thank you Ankit.

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