Reputation: 5981
we have an application that runs MS Word (hidden) to print documents.
If one of the printers has a problem, then Word hangs while waiting for the spooler to return the 'queued' message.
We have found that if we make Word visible (by using VBA in Excel with GetObject
and oWordApp.visible=true
for example) then the process continues printing the other documents with no problem.
We would like to make this more automatic by having a VBScript check for Word in running processes, if it finds it, make it visible, wait for a few seconds, hide it, and quit...
But I have a problem that the VBScript GetObject
function instantiates Word if it's not already running.
how should I check that word is running using VBScript without creating an instance of it?
here is the code I have in my VBScript file:
dim oWord, WScriptShell
set oWord = getobject("", "Word.Application")
set WScriptShell = CreateObject("WScript.Shell")
if isobject(oWord) then 'and oWord.Documents.count>0
wscript.echo("Word is running")
oWord.visible=true
WScript.Sleep 1000
oWord.visible=false
else
wscript.echo("Word not running")
end if
so what should I use to check if word is running without creating an instance of it?
Upvotes: 2
Views: 3683
Reputation: 6856
Just change GetObject("", "Word.Application")
to GetObject(, "Word.Application")
and it doesn't start an instance.
But this throws an error if Word is not running, so you can use it like this:
msgbox wordIsRunning
function wordIsRunning
dim wdApp
on error resume next
set wdApp = GetObject(, "Word.Application")
wordIsRunning = (err.Number = 0)
set wdApp = nothing
end function
Upvotes: 6
Reputation: 2940
Word hangs
check "DisplayAlerts" property. allowed only if property "Visible" set to "True".
tasklist /FI "IMAGENAME eq winword.exe"
will show you, does m$word running or not
Upvotes: 0