how to not allow other users to save a workbook that had been saved once?

fadwa9779

New Member
Joined
Sep 12, 2017
Messages
2
hi. i'm new to vba and would appreciate some assistance.

once I save a workbook, how can I prevent other users (an myself as well) from saving again into the same workbook? in other words, once the sheet is saved once, I don't want to allow further save(s), be it through a save prompt message or any other form.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hello Fadwa, welcome to Mr. Excel. The method below will work, but an important caveat is that there is no such thing as foolproof or unhackable techniques. This will help prevent somebody from saving over a file, but a determined enough person will get around any protection you put on the file.

In the VBA editor (accessed by pressing Alt + F11), double click on the ThisWorkbook object. This will open up a "blank canvas" where you can put code in. Put the following code in there AFTER you have initially saved the file for the first time. If you put it in before you save it the first time, you won't be able to save it at all. Also, make sure you save the file with a .xlsm file extension, NOT the regular .xlsx file extension

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
End Sub

Now, to get it work, put the cursor on the "Cancel = True" line and press F9. This puts a temporary stopping point on the cancellation line of code. Now click the Save or Save As button. You will see a yellow arrow appear to the left of the paused line of code. Drag the arrow down to the "End Sub" line and then press F8. This temporarily bypasses the cancellation, allowing you to save the file with the code in it. Now, whenever you open the file, you will be unable to save it using either the Save or Save As commands.

To explain what it is doing, this is called event code, which means it runs when something happens rather than when you tell it to run directly. In this case, it's looking at the BeforeSave event, which means in English that the code contained in it should run first whenever anyone tries to save the file. The Cancel variable can be either True or False. If it's False, the user is allowed to save normally. If it's True, then the entire saving procedure is terminated. By putting this code in, the Cancel variable will always be set to True, which will stop somebody from saving. You can put a password on your project as well by clicking Tools --> VBAProject Properties and going to the Protection tab. This puts a password on your code so that somebody can't come along and bypass the code altogether. Again, even this password can be easily broken, but it does make it harder for someone to change things. See if this works for you!
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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