Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = Not blnClose
End Sub
Private Sub Workbook_Open()
blnClose = False
End Sub
Public blnClose As Boolean
Public Sub Close_Code()
blnClose = True
ThisWorkbook.Close
End Sub
ADVERTISEMENT
Private Sub Workbook_Deactivate()
OnOff True
End Sub
Private Sub Workbook_Open()
OnOff False
End Sub
Private Declare Function DeleteMenu Lib "user32.dll" ( _
ByVal hMenu As Long, _
ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Private Declare Function DrawMenuBar Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetSystemMenu Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal bRevert As Long) As Long
Private Const MF_BYCOMMAND = &H0
Private Const SC_CLOSE = &HF060
Sub OnOff(blnOn As Boolean)
Dim hWndMenu As Long
If blnOn = False Then
hWndMenu = GetSystemMenu(Application.hwnd, 0&)
If hWndMenu <> 0 Then
DeleteMenu hWndMenu, SC_CLOSE, MF_BYCOMMAND
DrawMenuBar Application.hwnd
End If
Else
hWndMenu = GetSystemMenu(Application.hwnd, -1)
DrawMenuBar hWndMenu
End If
End Sub
am I being thick by not adding this code in the correct area?