OLE Automation to launch MS Word and bring to front

后端 未结 1 1269
情话喂你
情话喂你 2020-12-21 05:22

What is the \"correct\" (recommended) method for connecting to a running instance of MS Word and bringing this application to the front? I am doing something like the follow

相关标签:
1条回答
  • 2020-12-21 05:59

    Word (and Excel for that matter) will ONLY register the VERY FIRST INSTANCE that loads in the ROT (Running object table).

    The ROT is where GETOBJECT "gets the object", so, in certain circumstances, its' possible to have two instances of WinWord.exe loaded, one visible, one not, but the invisible instance is the one registered in the ROT and the visible one is NOT.

    That'll get you the behavior you're seeing.

    Unfortunately, without some API calls to enumerate all the open windows on the system, you always run the risk that GETOBJECT won't get you the object that you're expecting it to.

    There's not much of a way around this.

    Besides, you're end goal is a bit suspect anyway.

    When you say "What is the "correct" method for connecting to a running instance of MS Word and bringing this application to the front?", what happens if there are 2 or more actual instances of Winword.exe loaded?

    Which would you want to "connect" to and bring to the front. that's a roll of the dice anyway, unless you're specifically interested in a particular DOCUMENT window that's open.

    From what I understand, Word will register ALL document windows in the ROT, regardless of which instance of Winword it is, so you could theoretically Use Getobject to retrieve a particular DOCUMENT, get the APPLICATION object from the DOCUMENT object and then make it VISIBLE with a NORMAL windowstate.

    Here's an example of GetObject for a document

    http://support.microsoft.com/kb/307216

    0 讨论(0)
提交回复
热议问题