ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   close excel (https://www.excelbanter.com/excel-programming/361402-close-excel.html)

anonymousA

close excel
 
If you want to close all running instances of Excel, use code like

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Const WM_CLOSE = &H10


Private Sub CloseAllExcels()
Dim XLHwnd As Long
XLHwnd = FindWindow("XLMAIN", vbNullString)
Do Until XLHwnd = 0
SendMessage XLHwnd, WM_CLOSE, 0&, 0&
XLHwnd = FindWindow("XLMAIN", vbNullString)
Loop
End Sub

AA2e72E

close excel
 

A solution out of thin air!

AND a copy of a response by another person, just a few days ago!!!!


All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com