View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter Huang Peter Huang is offline
external usenet poster
 
Posts: 115
Default Peter Huang, Vasant, Chip Pearson - Close External Application VBA - ZABU

Hi ZABU,

It is strange that your code works for me.
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal HWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam
As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Const WM_CLOSE = &H10
Private Const WM_DESTROY = &H2
Private Const WM_NCDESTROY = &H82


Sub CloseWindow()
Dim HWnd As Long
'Dim lpClassName As String
'Dim lpWindowName As String

HWnd = FindWindow("SciCalc", "Calculator")
If HWnd 0 Then
SendMessage HWnd, WM_CLOSE, 0, 0
End If
End Sub

What is your problem, can not close the window or can not find the window?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.