Hello Everyone,
I am trying to prevent the save prompt when the 'X' at the top right of the sheet is used to close a file. I have all the usual stuff and I have been trying to embellish it with extra event enabling and extra Alerts = False etc, but nothing will prevent the prompt if the X is used. The following code is situated in Excel Objects: "ThisWorkbook". Should I put this code onto each sheet? There are several in this particular workbook. Any help would be greatly appreciated.
Thanks in advance,
David
I am trying to prevent the save prompt when the 'X' at the top right of the sheet is used to close a file. I have all the usual stuff and I have been trying to embellish it with extra event enabling and extra Alerts = False etc, but nothing will prevent the prompt if the X is used. The following code is situated in Excel Objects: "ThisWorkbook". Should I put this code onto each sheet? There are several in this particular workbook. Any help would be greatly appreciated.
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Application.EnableEvents = True
ThisWorkbook.Saved = True
Application.DisplayAlerts = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Application.EnableEvents = True
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Cancel = True
Application.DisplayAlerts = True
End Sub
David