If you mean the workbook window, protect the workbook. If you mean Excel
itself
you need to use the Windows API to disable the "system menu". Code
previously posted by Rob Bovey
Attribute VB_Name = "MSystemMenu"
Option Explicit
Option Private Module
''' **************************************
''' Module Constant Declaractions Follow
''' **************************************
''' Deletes the menus by position (this is our default).
Private Const MF_BYPOSITION As Long = &H400
''' Deletes the menu by Command ID. This is rarely used
''' and is shown here for information purposes only.
Private Const MF_BYCOMMAND As Long = &H0
''' This is the number of items on the system menu
Private Const mlNUM_SYS_MENU_ITEMS As Long = 9
''' **********************************
''' Module DLL Declarations Follow
''' **********************************
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
''''''''''''''''''''''''''''''''''''''''''''
''' Comments: Deletes the system control
''' menu of the specified window.
'''
''' Date Developer Action
''' -----------------------------------------
''' 09/12/01 Rob Bovey Created
'''
Public Sub DeleteSystemMenu()
Dim lHandle As Long
Dim lCount As Long
''' Just blow by any errors
On Error Resume Next
lHandle = FindWindowA(vbNullString, Application.Caption)
''' Only continue if the passed window handle isn't zero.
If lHandle <> 0 Then
''' There are 9 items on the application control menu.
''' Loop through and disable each one.
For lCount = 1 To mlNUM_SYS_MENU_ITEMS
''' The nPosition of the DeleteMenu function will always be 0,
''' because as we delete each menu item, the next one moves up
''' into the first position (index of 0).
DeleteMenu GetSystemMenu(lHandle, False), 0, MF_BYPOSITION
Next lCount
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''
''' Comments: Restores the Excel system control.
'''
''' Date Developer Action
''' ----------------------------------------------
''' 09/12/01 Rob Bovey Created
'''
Public Sub RestoreSystemMenu()
Dim lHandle As Long
On Error Resume Next ''' Just blow by any errors
lHandle = FindWindowA(vbNullString, Application.Caption)
''' Passing True to the bRevert
''' argument of the GetSystemMenu API restores
''' the control menu of the specified window.
GetSystemMenu lHandle, True
End Sub
Regards,
Tom Ogilvy