MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Application & Workbook Command Buttons

Posted by Tony Moses on April 12, 2000 4:31 AM

How can I disable the 3 command buttons found at the top right corner of both the application window and the active workbook (minimize, resize, and close)?

Posted by Ivan Moala on April 13, 2000 2:05 AM

These functions will disable the Application window BUT not the workbook window.

Option Explicit
Dim hWnd ' Handle of activewindow
Dim hMenu% ' SystemMenu of hWnd

Declare Function GetActiveWindow Lib "User32" () As Integer

Declare Function GetSystemMenu Lib "User32" (ByVal hWnd As Integer, _
ByVal bRevert As Integer) As Integer

Declare Function DeleteMenu Lib "User32" (ByVal hMenu As Integer, _
ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

'The following procedure disables Application Win
Sub Disable_Control()
Dim x As Integer
For x = 1 To 9
'Delete the first menu command and loop until
'all commands are deleted
Call DeleteMenu(GetSystemMenu(GetActiveWindow, False), 0, 1024)
Next X
End Sub

'The following procedure restores the Control menu
Sub RestoreSystemMenu()
'get the window handle of the Excel application
hWnd = GetActiveWindow()
'restore system menu to original state
hMenu% = GetSystemMenu(hWnd, 1)
End Sub