Code to prevent saving preventing me from saving code to prevent saving - LOL

ktielens

New Member
Joined
Oct 26, 2015
Messages
23
I am using the following code to prevent users from saving a document. The problem is, I can't save the code in the document either as it's preventing all saving. OMG!!! How funny.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "Please don't use the save button"
Cancel = True
End Sub

Please help.
 
Oh, I see.
I thought you already had that code in a book, and were now trying to add some other code but couldn't because it was preventing save.
I get it now.

I thought there was a simpler way, but you can put a keyword in some designated cell
And add an If to test that cell for a specific value
If that specific value is in the cell, proceed with the save, if Not, then cancel the save.

I used A1 on Sheet1 - adjust as needed.
If you put Go in that cell (Case sensitive) it will allow you to save.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Sheets("Sheet1").Range("A1").Value = "Go" Then
    Sheets("Sheet1").Range("A1").ClearContents
    Exit Sub
End If
MsgBox "Please don't use the save button"
Cancel = True
End Sub

Thanks. I like how there are multiple ways of doing things. Your expertise is much appreciated!
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,216,075
Messages
6,128,662
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top