preventing closure of active excel window

  • Thread starter Thread starter cyclingsal
  • Start date Start date
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top