Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open an App (Word) then wait 1

Status
Not open for further replies.

JPJeffery

Technical User
May 26, 2006
600
0
0
GB
I know how to open Word but what I can't get the VBScript to do is wait until that instance of Word has been Quit before continuing...

It's just got to be possible with a WHILE loop hasn't it, but which event can we test to change a variable that quits the loop?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
You monitor quit event callback. To do so, you create the application instance with wscript's createobject method. Like this.
[tt]
bquit=false 'global in scope
wordfile="d:\test\xyz.doc"

set oword=wscript.createobject("word.application","oword_")
oword.visible=true
oword.documents.open wordfile
do while not bquit
wscript.sleep 1000
loop
set oword=nothing
wscript.echo "word application quitted"

sub oword_quit
bquit=true
end sub
[/tt]
 
I've been trawling the net for about a day trying to find a beautifully simple solution like this.

Thanks!

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Question though, what does the
Code:
"oword_")
do in
Code:
set oword=wscript.createobject("word.application","oword_")
?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
It is just the prefix of the event handler, quite arbitary. You can call it "whateverprefix_", for instance, as long as you name the handler "sub whateverprefix_quit".
 
Nice one. Interesting stuff there.

Thanks again.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Hmm, is there any particular reason why this won't work with Internet Explorer?
Code:
Sub HereIsTheNews()
Set objIE = wscript.CreateObject("InternetExplorer.Application","objIE_")
    If Err.Number <> 0 Then
        On Error GoTo 0
        Msg = "IE application not found."
        MsgBox Msg,vbExclamation,Msg
        Wscript.Quit
    End If
    On Error GoTo 0

    objIE.visible = true
    objIE.ToolBar = 0
    objIE.statusbar=false
    objIE.Navigate "file://" & strNewsPage
'    objIE.Activate
    wscript.echo "bQuit = " & bQuit
    do while not bQuit
        wscript.sleep 500
    loop
    wscript.echo "Internet Explorer has been closed down"
End Sub
'---------------------------------------------------------
Sub objIE_quit
wscript.echo "objIE_quit has been called"
    bQuit=true
End Sub

Come to think of it, why doesn't objIE.Activate work?

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Nope, t'aint that either...

:-(

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
>Sub objIE_quit
[tt]Sub objIE_[blue]on[/blue]quit[/tt]
That's how different applications set their event models slightly differently.
 
Eek! Nice of MS to be consistent.

Where's the best place to look this stuff up (i.e. which methods work with with apps)?

Cheers

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Muy bueno!

Now THAT'S a resource...

Thanks again, tsuji.

JJ
[small][purple]Variables won't. Constants aren't[/purple][/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top