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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command to kill external program

Status
Not open for further replies.

Brackenneff

Technical User
Jun 24, 2003
2
US
I need to kill an external program from my VBA routine. Is there code to do this? Or can I shell to another program and pass it a parameter to do this?
 
Using Windows Calculator as an example.

'---------------------------------------------------------
Private Declare Function BringWindowToTop Lib "user32.dll" _
(ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" _
Alias "FindWindowA" (ByVal lpClassName _
As Any, ByVal lpWindowName As Any) As Long
'------------------------------------------
Sub GET_WINDOW()
Dim MyWindowName As String
Dim xHwnd As Long
'------------------
Shell "C:\Calc.exe", 1
MyWindowName = "Calculator"
xHwnd = FindWindow(CLng(0), MyWindowName)
retval = BringWindowToTop(xHwnd)
Application.Wait Now + TimeValue("00:00:04")
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.
End Sub
'-------------------------------------------



Regards
BrianB
** Let us know if you get something that works !
================================
 
Generally, if you are controlling it from VBA and it is another M$ program,
application.quit
should work

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
Get the best answers to your questions - faq222-2244
 
KUDOS to BrainB... those were a couple of excellent functions. They worked like a charm for calculator, but I'm still having some trouble gettting it to close my VB app. It's interesting... when Excel sends the "Alt + F4" command to my VB program, it's Excel that responds to the command, even though it brought my VB app to the foreground. I'll figure that one out, though. Thanks for the help!!
 
Check out what keyboard commands close your app (open menu and eXit ?) and use them. eg. Alt+F then X. See SendKeys in VB Editor help.



Regards
BrianB
** Let us know if you get something that works !
================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top