How do i close i an application by VBA? (Repost)

A

Avi

Hello,

I open an application via this code that works fine
Sub LaunchCaptureExpress()
Dim RetVal As Long
RetVal = Shell("C:\Program Files\Capture
Express\capexp.exe", vbNormalFocus)
End Sub

How do i close it???

I was given the following solution by "chijanzen", but i get an error message " AciveX does'nt support object" that refers to "Set WshShell = CreateObject("Wscript.Shell")"

close the Windows after 10 seconds
Sub LaunchCaptureExpress()
Dim WshShell As Object
Dim oExec As Object
Set WshShell = CreateObject("Wscript.Shell")
Set oExec = WshShell.Exec("C:\Program Files\Capture
Express\capexp.exe")
DoEvents
Application.Wait (Now + TimeValue("0:00:10"))
oExec.Terminate
Set WshShell = Nothing
Set oExec = Nothing
End Sub


Could you help?

Thanks a lot
 
L

Leith Ross

Hello Avi,

The WSH refers to *Windows Scripting Host*. You will need to add a
reference to this library in your VBA project. On the VBA editor
toolbar select "*Tools*" and the "*References...*". Look in the list
for Windows Scripting Host and check it and click OK. Now the code will
run.

Sincerely,
Leith Ross
 
T

Tom Ogilvy

Perhaps you can do something by using these articles and their links:

http://support.microsoft.com/kb/129796/EN-US/

http://support.microsoft.com/default.aspx?scid=kb;en-us;176391

http://support.microsoft.com/default.aspx?scid=kb;en-us;129797

--
Regards,
Tom Ogilvy

Hello,

I open an application via this code that works fine
Sub LaunchCaptureExpress()
Dim RetVal As Long
RetVal = Shell("C:\Program Files\Capture
Express\capexp.exe", vbNormalFocus)
End Sub

How do i close it???

I was given the following solution by "chijanzen", but i get an error
message " AciveX does'nt support object" that refers to "Set WshShell =
CreateObject("Wscript.Shell")"

close the Windows after 10 seconds
Sub LaunchCaptureExpress()
Dim WshShell As Object
Dim oExec As Object
Set WshShell = CreateObject("Wscript.Shell")
Set oExec = WshShell.Exec("C:\Program Files\Capture
Express\capexp.exe")
DoEvents
Application.Wait (Now + TimeValue("0:00:10"))
oExec.Terminate
Set WshShell = Nothing
Set oExec = Nothing
End Sub


Could you help?

Thanks a lot
 
T

Tom Ogilvy

Avi,
Here is an additional thought. if you run this

Sub ABC()
Dim WshShell as Object
set WshShell = CreateObject("Wscript_Tom.Shell")
End Sub
and get the same error message on the CreateObject line, then you don't have
the Windows Scripting Host Installed.

The message you cited isn't exactly the same as what I get, but it may be
you are using a non-english version of windows and you were posting a
translation of the message.
 
T

Tom Ogilvy

Also, see your first posting of this question. You have an answer from RB
Smissaert.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top