Hi - I am trying to put in a custom dialogue & warning before an user closes the workbook.
The code is working fine in all basic / primary requirements with the exception of a small glitch.
When user tries to close the workbook, the code will give a warning to the user.
If user hits "No" code cancels the workbook close and brings them back to the sheet.
If user hits "Yes" code closes the workbook without saving.
Problem: The warning message comes up twice when user hits "no", i.e. the user has to hit "no" twice.
Any help would be appriciated! Also, if you can suggest a shorter method, most welcome!
Many thanks in advance
Below is my code. Please feel free to as for more details if required.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Wtxt As String
'suppress alerts
Application.DisplayAlerts = False
'to allow closing without saving changes to workbook
ActiveWorkbook.Close savechanges:=False
'Warning text
Wtxt = "You are closing this file;" & vbCr & _
"All changes shall be removed and file reset to default state." & vbCr & _
& vbCr & "Are you sure?"
Inp = MsgBox(Wtxt, vbQuestion + vbYesNo, "Warning!")
If Inp = vbNo Then
Cancel = True
Application.DisplayAlerts = True
Exit Sub
Else
'functions to clean up the workbook and return it to default state
Call Cleaner
Call Show_Form
End If
End Sub
The code is working fine in all basic / primary requirements with the exception of a small glitch.
When user tries to close the workbook, the code will give a warning to the user.
If user hits "No" code cancels the workbook close and brings them back to the sheet.
If user hits "Yes" code closes the workbook without saving.
Problem: The warning message comes up twice when user hits "no", i.e. the user has to hit "no" twice.
Any help would be appriciated! Also, if you can suggest a shorter method, most welcome!
Many thanks in advance

Below is my code. Please feel free to as for more details if required.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Wtxt As String
'suppress alerts
Application.DisplayAlerts = False
'to allow closing without saving changes to workbook
ActiveWorkbook.Close savechanges:=False
'Warning text
Wtxt = "You are closing this file;" & vbCr & _
"All changes shall be removed and file reset to default state." & vbCr & _
& vbCr & "Are you sure?"
Inp = MsgBox(Wtxt, vbQuestion + vbYesNo, "Warning!")
If Inp = vbNo Then
Cancel = True
Application.DisplayAlerts = True
Exit Sub
Else
'functions to clean up the workbook and return it to default state
Call Cleaner
Call Show_Form
End If
End Sub