VBA Tip: Prevent an Excel File From Being Saved

If an Excel file that you have created requires macros to be activated in order to work properly and you would like to prevent any modifications to the file from being saved, it's possible to do this and it will only take a second.


Open your file with macros disable and paste the following code into ThisWorkbook:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True 'Cancels any request to save the file
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Application.ThisWorkbook.Saved = True 'Tells Excel that the file has already been saved (this prevents Excel from requesting that you save the file when you close it)
End Sub

All you have left to do is to save your file (you will always be able to save the file as long as macros are disabled).