VBA to prevent saving workbook

herbc0704

Board Regular
Joined
Jun 22, 2009
Messages
100
I am working in Excel 2013. Is there a VBA to prevent the user from saving or save as to another location? Also, is there a way to turn off this VBA only by me when I have to make changes to the workbook?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi,
There are certainly ways to prevent saving a workbook but, as you've guessed, it would be difficult to save it like that so it will work the way you want for the next user. About the quickest solution that comes to mind (without any coffee yet...) would be to require a password before allowing to save.
You can try something like this in your ThisWorkbook code module.
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim PW As String
PW = InputBox("Enter a password to save this file.", "Password To Save")
If PW <> "MyPassword" Then Cancel = True
End Sub

(Obviously, you'll need to replace 'MyPassword' with whatever your password is...)

As stated earlier, there are plenty of ways to achieve this, including testing for the username and allowing/disallowing to save depending on who the user is, but this is about the quickest way to get there that I can think of right now.

Hope it helps.
 
Upvote 0

Forum statistics

Threads
1,203,541
Messages
6,056,006
Members
444,840
Latest member
RazzelDazel

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