Word (and Excel, for that matter) will ONLY register the VERY FIRST INSTANCE, which is loaded into the ROT (desktop table).
ROT is where GETOBJECT "receives the object", so under certain circumstances it "can load two instances of WinWord.exe, one visible, one not, but an invisible instance - one that is registered in ROT and visible - NOT.
This will give you the behavior you see.
Unfortunately, without some API calls to list all open windows in the system, you always risk that GETOBJECT will not give you the object that you expect from it.
Not much here.
In addition, you end up suspecting a little.
When you say “What is the“ correct ”method to connect to a running instance of MS Word and bring this application to the forefront?”, What happens if 2 or more actual instances of the downloaded Winword.exe file are loaded?
What would you like to “connect” and bring to the fore. that a roll of dice in any case, unless you are specifically interested in a separate document window that opens.
From what I understand, Word will register ALL document windows in ROT, no matter what instance of Winword it is, so theoretically you could use Getobject to retrieve a specific DOCUMENT, get the APPLICATION object from the DOCUMENT object and then do this VISIBILITY with NORMAL windowstate.
Here is a GetObject example for a document
http://support.microsoft.com/kb/307216
Darinh
source share