none
Is Word ready for COM use RRS feed

  • Question

  • I am talking to Word as a COM server in a program that makes documents with Word as the document engine.

    The program can load Word on a user request  or switch to Word if Word is already loaded. At different sites Word may use one or several Word Addins. All the addins are dotm files and are in the Word startup folder. Observations show Word takes approximately 10 seconds to load the addins. Fewer addins results in a shorter load time.

    One addin has macros the program uses in making documents. One way to load Word on request and manage it is to wait 10 sec before talking to Word. I am wondering if there are better ways?

    1. When Word is loading will it respond to core requests such as "Is AddIN ABC loaded?"

    2. Is there a way to ask Word "Are you open for business?"


    Sunday, March 15, 2015 11:50 PM

Answers

  • Thanks for comments. The problem I had occurred when I asked MS Word to do some internal-to-Word action such a as inserting a document variable to the active document or running a macro (with or without parameters) from the dotm file used. The dotm file is loaded from Word's startup folder.

    The problem was the call faulted. I am using the TWordApplication component (Embarcadero) to connect to Word. Stress testing of this component shows it to be robust and I find no faults with it. At least in the tests I used.

    A serendipitous discovery showed that when a user had left a dialog open in MS Word which expected a user response then Word  was not accepting my requests for service. Now when this happens I ask the user to check if Word is waiting for a response from them. Deal with it then try again.

    Errors are down to 0 now with users "encouraged" not to leave dialog boxes hanging open in Word.

    Tuesday, April 14, 2015 1:23 AM

All replies

  • Hi Russell

    Well, one possible approach would be to start Word using a Command Line that does not load add-ins; you can find more information here: http://support.microsoft.com/en-us/kb/210565

    Another one is to isolate a command that's causing problems (returning an error) and check for that error in a loop. When it no longer occurs, the assumption would be that Word is ready.

    << am talking to Word as a COM server in a program that makes documents with Word as the document engine.>>

    This isn't recommended or really supported, which is one reason Word doesn't expose the functionality you're looking for. The "correct" way to generate Word documents is to work directly with the Open XML file format, which doesn't require the Word application at all. You can find more information at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, March 16, 2015 2:57 PM
    Moderator
  • Thank you Cindy for your reply and suggestions. The program which makes documents with user interaction needs the add-ins for services to the user such as presenting choices of sub-documents to users, and more. So using Word without loading add-ins is not possible. The program is in use at several sites using different OSes and Office/Word versions. XP to Win 8 and Word 2003 to Word 2013. Word vba macros provide sufficient services to enable the program.

    Two issues have me looking for insight. The first is knowing when MSWord has loaded itself and is open for business. Cindy's suggestion here, if I understand the reply, is to loop at a command until it is successful. Ican try that and see how it goes. 

    I have a second related topic I am looking at and when I can describe it better I'll report or ask again here.


    Monday, March 23, 2015 7:13 PM
  • Thanks for comments. The problem I had occurred when I asked MS Word to do some internal-to-Word action such a as inserting a document variable to the active document or running a macro (with or without parameters) from the dotm file used. The dotm file is loaded from Word's startup folder.

    The problem was the call faulted. I am using the TWordApplication component (Embarcadero) to connect to Word. Stress testing of this component shows it to be robust and I find no faults with it. At least in the tests I used.

    A serendipitous discovery showed that when a user had left a dialog open in MS Word which expected a user response then Word  was not accepting my requests for service. Now when this happens I ask the user to check if Word is waiting for a response from them. Deal with it then try again.

    Errors are down to 0 now with users "encouraged" not to leave dialog boxes hanging open in Word.

    Tuesday, April 14, 2015 1:23 AM