Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Close Window

Is it possible to close a programme window, after opening it with the shell
command in VBA?.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Close Window

Mark,

It depends on the program. One method that may work is to send a
CLOSE message to the window.


Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" _
(ByVal HWND As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Sub CloseProgram()
Dim HWND As Long
Const WM_CLOSE = &H10

HWND = FindWindow(vbNullString, "Calculator") '<<<<
If HWND 0 Then
SendMessage HWND, WM_CLOSE, 0&, 0&
End If
End Sub

Change the "Calculator" in the line marked with <<< to the
caption of the program window you want to close.



"mark" wrote in message
news:SZoZb.135$Td6.11@newsfe1-win...
Is it possible to close a programme window, after opening it

with the shell
command in VBA?.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Close Window

Thank you for your help with the code, runs fine and executes the line
"SendMessage HWND, WM_CLOSE, 0&, 0&"
but the windows doesn't close. The window I am trying to close is a web page

"Chip Pearson" wrote in message
...
Mark,

It depends on the program. One method that may work is to send a
CLOSE message to the window.


Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" _
(ByVal HWND As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Sub CloseProgram()
Dim HWND As Long
Const WM_CLOSE = &H10

HWND = FindWindow(vbNullString, "Calculator") '<<<<
If HWND 0 Then
SendMessage HWND, WM_CLOSE, 0&, 0&
End If
End Sub

Change the "Calculator" in the line marked with <<< to the
caption of the program window you want to close.



"mark" wrote in message
news:SZoZb.135$Td6.11@newsfe1-win...
Is it possible to close a programme window, after opening it

with the shell
command in VBA?.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
close find window Gklass Charts and Charting in Excel 1 October 24th 07 10:21 AM
Close Excel mac help window BillyC in Ross Excel Discussion (Misc queries) 0 August 5th 06 07:25 PM
close window trapping Yury Lobanov Excel Programming 2 December 23rd 03 05:55 PM
Close explorer window from excel VBA Itzik[_2_] Excel Programming 0 October 1st 03 02:58 PM
Close Browser window with VBA brianelson Excel Programming 1 July 12th 03 05:35 AM


All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"