WScript.GetObject doesn't get running Word App 
Author Message
 WScript.GetObject doesn't get running Word App

My environment:
Windows NT 4.0 SP6a, WSH 5.6

My problem:
I have a running Word (document), i.e. one instance of winword.exe. Now
the following VBS Script within WSH should allow me to do some event
handling:

SUB WordEventDocumentChange()
   CALL MsgBox ("Event fired")
END SUB

SET MyApp = WScript.GetObject("","Word.Application","WordEvent")

DO WHILE TRUE
   WScript.Sleep (1000)
LOOP

When I execute the Script the running Word (object) isn't selected but
an addtional instance of winword.exe is started (TaskMgr). Also Clicking

in the original running word window doesn't fire the MsgBox. So it seems

that the WScript.GetObject Method can't reuse the running application
but always starts a new instance.
(If I WScript.CreateObject a new instance with an Event Prefix, the
event fires.)

Any hints?
Thansk, Gnther



Mon, 08 Aug 2005 23:27:37 GMT  
 WScript.GetObject doesn't get running Word App

Quote:
> SUB WordEventDocumentChange()
>    CALL MsgBox ("Event fired")
> END SUB

SET MyApp = GetObject(,"Word.Application")
CALL WScript.ConnectObject(MyApp,"WordEvent")

Quote:
> DO WHILE TRUE
>    WScript.Sleep (1000)
> LOOP

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp



Tue, 09 Aug 2005 08:36:42 GMT  
 WScript.GetObject doesn't get running Word App
How to do it when I would like to use the WSH METHOD GetObject, NOT the
VBS FUNCTION? Like in my example: WScript.GetObject(...)

It is documented that it should work any way. But omitting the first
parameter issues an error, it is not allowed. Is that a BUG? Or anything
omitted in the GetObject Method documentation?

Thanks!
Gnther

"Michael Harris (MVP)" schrieb:

Quote:
> > SUB WordEventDocumentChange()
> >    CALL MsgBox ("Event fired")
> > END SUB

> SET MyApp = GetObject(,"Word.Application")
> CALL WScript.ConnectObject(MyApp,"WordEvent")

> > DO WHILE TRUE
> >    WScript.Sleep (1000)
> > LOOP

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US

> Technet Script Center
> http://www.microsoft.com/technet/scriptcenter/default.asp



Tue, 09 Aug 2005 17:23:51 GMT  
 WScript.GetObject doesn't get running Word App

Quote:
> How to do it when I would like to use the WSH METHOD GetObject, NOT the
> VBS FUNCTION? Like in my example: WScript.GetObject(...)

You can't...

Quote:

> It is documented that it should work any way. But omitting the first
> parameter issues an error, it is not allowed. Is that a BUG? Or anything
> omitted in the GetObject Method documentation?

A quote from the Remarks section of the current WSH documentation for the
GetObject method...

"... The GetObject method always returns the same instance when called with
the zero-length string syntax (""), and it causes an error if you do not
supply the path parameter. ...".

Earlier versions of the docs were cloned from the original VB/VBA/VBScript
documentation.  The same is true for the JScript GetObject() docs.  It could
never work in JScript since JScript can't omit optional arguments anyway.
The JScript docs are still not 100% correct, implying at one point that the
argument can be omitted but later includes the same statement as quoted
above.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US

Technet Script Center
http://www.microsoft.com/technet/scriptcenter/default.asp



Wed, 10 Aug 2005 09:36:55 GMT  
 WScript.GetObject doesn't get running Word App
Hello Michael!

Quote:
> A quote from the Remarks section of the current WSH documentation for the
> GetObject method...
> "... The GetObject method always returns the same instance when called with
> the zero-length string syntax (""), and it causes an error if you do not
> supply the path parameter. ...".

May I quote the BEGINNING of the WSH WScript.GetObject Method documentation:
:-)

GetObject Method:
Retrieves an existing object with the specified ProgID, or ...
Remarks
Use the GetObject method when an instance of the object exists in memory, or ...

Gnther



Fri, 12 Aug 2005 17:01:11 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. WScript.GetObject doesn't get running Word App

2. WScript.Shell Run Doesn't Work???

3. Wscript.shell Run doesn't work

4. GetObject() in VBScript on web page doesn't work

5. GetObject() in VBScript on web page doesn't work

6. GetObject doesn't work from VBScript

7. Getting Word to Open as an App, not in IE

8. i need help with 'wscript.run'

9. i need help with 'wscript.run'

10. LW Select 360 doesn't print with MS WORD

11. GrimeScript: : Doesn't work with WORD files!

12. Long running html apps (.hta's)

 

 
Powered by phpBB® Forum Software