开发者

Problem with interop.word in a .net application

Solution Environment:

MS Visual Studio 2010 Ultimate, MS Office 2010 Professional, Microsoft Interop classes

Scenario:

I've created a .Net application which uses the Interop classes to i开发者_如何学Gonteract with MS Word. Consider this: An application which mimics a key-value pair table. When the user clicks on the "value" field, the .net application opens up a winword window where the user can enter some notes. Upon clicking close (winword), .net app will do a winword.wordopenxml and save the data in the field. For this to happen, i've added event handles to winword. The application runs perfectly fine. The problem arises when i have multiple instances of winword opened (separately by the user but not thru the .net application) . The event handlers from the .net application is applied to all instances of winword and hence, upon closing just one instance word, all the other instances gets closed too. I tried different ways to initialize the word object in the application. I also tried the work around "Initializing two instances of winword and quit the first instance" -> This approach also did not work well.

Gurus: Could you please help me find a suitable solution for this problem ?

-Rupesh


This is not what is really going on. It may look like you have multiple instances of Word running but there really is only one. Word is a very large program that requires a lot of system resources. When the user starts another copy, that copy checks if Word is already running and asks it to open the document. And quits. The original instance just creates another window, it otherwise indeed looks exactly like another instance of Word.

So when you make Word exit, you kill all the other windows as well. Use Taskmgr.exe, Processes tab to verify this. As a workaround, consider enumerating the Documents collection to see what else is opened.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜