ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   preventing closure of active excel window (https://www.excelbanter.com/excel-programming/296181-preventing-closure-active-excel-window.html)

cyclingsal

preventing closure of active excel window
 
Hi,

I wish to prevent users from closing the active excel window with the
window close button (x). I would like them to use a macro-linked
button for that. Is there a way to code this into VBA such that the
(x)-button is disabled?

Thanks
Sal

Nigel[_8_]

preventing closure of active excel window
 
The following was supplied courtesy of Michel Pierron, you need to put it in
the workbook code. It works for me in Excel2002.

Private Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function GetSystemMenu& Lib "user32" _
(ByVal hWnd As Long, ByVal bRevert As Long)
Private Declare Function DeleteMenu& Lib "user32" (ByVal hMenu As Long _
, ByVal nPosition As Long, ByVal wFlags As Long)
Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd As Long)
Private hWnd&

Private Sub Workbook_Activate()
DeleteMenu GetSystemMenu(hWnd, 0), &HF060, 0&
DrawMenuBar hWnd
End Sub

Private Sub Workbook_Deactivate()
GetSystemMenu hWnd, True
DrawMenuBar hWnd
End Sub

Private Sub Workbook_Open()
hWnd = FindWindow(vbNullString, Application.Caption)
End Sub

"cyclingsal" wrote in message
om...
Hi,

I wish to prevent users from closing the active excel window with the
window close button (x). I would like them to use a macro-linked
button for that. Is there a way to code this into VBA such that the
(x)-button is disabled?

Thanks
Sal




cyclingsal

preventing closure of active excel window
 
Thanks Nigel


All times are GMT +1. The time now is 07:38 AM.

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