Option Explicit
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare PtrSafe Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare PtrSafe Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Private Declare PtrSafe Function SetFocus Lib "user32" (ByVal hwnd As Long) As Long
Private Const GWL_STYLE As Long = (-16) '// The offset of a window's style
Private Const GWL_EXSTYLE As Long = (-20) '// The offset of a window's extended style
Private Const WS_SYSMENU As Long = &H80000 '// System menu bit
Private Const SC_CLOSE As Long = &HF060 'Constant to identify the Close menu item
'// Set or clear a bit from a style flag
Private Sub SetBit(ByRef lStyle As Long, ByVal lBit As Long, ByVal bOn As Boolean)
If bOn Then
lStyle = lStyle Or lBit
Else
lStyle = lStyle And Not lBit
End If
End Sub
Public Sub SetStyleHide()
Dim lStyle As Long, hMenu As Long
lStyle = GetWindowLong(Application.hwnd, GWL_STYLE)
If lStyle = 0 Then
MsgBox "Unable to determine application window handle...", vbExclamation, "Error"
Exit Sub
End If
SetBit lStyle, WS_SYSMENU, False
'Set the basic window styles
SetWindowLong Application.hwnd, GWL_STYLE, lStyle
'Get the extended window style
lStyle = GetWindowLong(Application.hwnd, GWL_EXSTYLE)
'// Not wanted - delete it from the control menu
hMenu = GetSystemMenu(Application.hwnd, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
Windows.Arrange ArrangeStyle:=xlTiled
'Update the window with the changes
DrawMenuBar Application.hwnd
SetFocus Application.hwnd
End Sub