Close an application with sendkeys

I

ina

Hello,

This is my code to open my program from excel;

Public Sub OpenPLaunchShell()
On Error GoTo Err_PLaunch

Dim strappPack As String
Dim BoPack As Boolean


On Error Resume Next

strappPack = "C:\Program Files\PLaunch\PLaunch.exe"



If Err <> 0 Then


BoPack = True ' if no error PLaunch is open
Err.Clear
MsgBox "PLaunch is not open"
Call Shell(strappPack, 2)
AppActivate strappPack
Exit Sub

Else
Exit Sub
MsgBox "Found PLaunch open"
End If

'Exit from the code
ExitCode:
Exit Sub

'Error Handler
Err_PLaunch:
MsgBox Err.Description
Resume ExitCode


End Sub


This is the sub to close my program; but the problem is that I close
the visual studio when I try to execute this code:


Sub ClosePLaunch()


Dim strappPack As String

strappPack = "C:\Program Files\PLaunch\PLaunch.exe"


'Close PLaunch
SendKeys "%{F4}", True
DoEvents

End Sub

Someone has any suggestion how to close an application on sending the
Alt+F4 key.

Ina
 
A

AA2e72E

If you know the Windows Handle of your application (Use the FindWindow API),
you can close it using the SendMessage or PostMessage API call.
 
I

ina

Thank you I used the createobject and now it is fine. but the program
open twice and I do not know why

Ina
 

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