Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Word
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 22-Apr-11 2:00am
2000 P569
Edited 22-Apr-11 3:31am
v3
Comments
Ankit Rajput at 22-Apr-11 8:35am
   
Please check the new solution.

1 solution

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

Solution 2

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
  Permalink  
v2
Comments
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 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 22 Apr 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