preventing closure of active excel window

C

cyclingsal

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
 
N

Nigel

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
 
Top