Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have this code in my workbook open module that disables the [X] button (close workbook) function.
This does the trick.
My Exit button, which is the recommended way of closing the workbook looks like this:
When the code in purple is executed, as it tries to close the workbook, the workbook close procedure kicks in naturally, and displays the message "Please use the application [EXIT] option to EXIT Excel." My question is, how can I avoid this instance of this message appearing?
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
MsgBox "Please use the application [EXIT] option to EXIT Excel.", vbInformation, "Sorry..."
End Sub
This does the trick.
My Exit button, which is the recommended way of closing the workbook looks like this:
Rich (BB code):
Sub front_exit()
Application.ScreenUpdating = False
mbevents = False
ui1 = MsgBox("Are you certain you wish to exit?", vbQuestion + vbYesNo, "Confirm exit")
If ui1 = vbNo Then
mbevents = True
Application.ScreenUpdating = True
Exit Sub
End If
'YES, exit
'reset page
With Worksheets("FRONT")
.Unprotect
.Range("E4") = "- Surname, Given -"
.Range("E4:G4").Font.Italic = True
.Range("E4:G4").Font.Size = 11
.Range("E4:G4").Font.Color = RGB(0, 0, 0)
.Range("E5") = "- Select -"
.Range("E5:F5").Font.Italic = True
.Range("E5:F5").Font.Size = 11
.Range("E5:F5").Font.Color = RGB(0, 0, 0)
.Protect
End With
'reset workbook
wkbk_on_close
'save and close workbook
ui1 = MsgBox("Are you sure you want to SAVE and close this application?", vbQuestion + vbYesNo, "Confirm SAVE before close")
If ui1 = vbYes Then
MsgBox "Changes saved."
ThisWorkbook.Close savechanges:=True
Else
MsgBox "No changes saved."
ThisWorkbook.Close savechanges:=False 'enabled once app is working well. We don't want any user unauathorized changes to save
End If
mbevents = True
Application.ScreenUpdating = True
End Sub
When the code in purple is executed, as it tries to close the workbook, the workbook close procedure kicks in naturally, and displays the message "Please use the application [EXIT] option to EXIT Excel." My question is, how can I avoid this instance of this message appearing?