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

Close another application from VBA 1

Status
Not open for further replies.

olekr

Instructor
May 27, 2001
19
NO
Hi folks!
Is there some way to close an application from VBA which is shown in task list as a process? For ex. Winzip?
Thanks. Ole
 
Have a look at:

you will need the code from
to get the api class name of the application, but it's pretty straight forward.

hth

Ben

----------------------------------------------
Ben O'Hara

"Where are all the stupid people from...
...And how'd they get so dumb?"
NoFX-The Decline
----------------------------------------------
 
Hi,

This is another way to close an app. Paste this in to a Module:

Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long

Public Const WM_CLOSE = &H10
Public gAppToClose As String

Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim slength As Long, TitleBar As String, retval As Long
Static winnum As Integer
winnum = winnum + 1
slength = GetWindowTextLength(hWnd) + 1
If slength > 1 Then
TitleBar = Space(slength)
retval = GetWindowText(hWnd, TitleBar, slength)
If InStr(TitleBar, gAppToClose ) Then
Call SendMessage(hWnd, WM_CLOSE, 0&, 0&)
End If
End If
EnumWindowsProc = 1
End Function

To close an app. Place this e.g. into the On Click event of a button:

gAppToClose = "Winzip"
Call EnumWindows(AddressOf EnumWindowsProc, 0)

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top