PDA

View Full Version : Disable SAVE/SAVE AS and Make Savable Again after Username and Password



rorobear
11-01-2020, 12:19 AM
Hello Everyone,
Hoping someone can help me out with this. I’ve disabled the SAVE and SAVE AS in my workbook. When the user tries to save, they are given a YES or No option. If YES is selected a LOGIN Form appears asking for a username and password. Everything works up until this part. What I can’t figure out is how to make the workbook savable again after the username and password has been supplied. Also, once changes are made and the workbook is closed, the process should start over when it reopens. Below is the code and I’ve attached the workbook. The username is hazmat and the password is 1012. Any assistance is greatly appreciated.


Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim Ans As VbMsgBoxResult
Ans = MsgBox("You can't save this workbook!" & vbNewLine & _
"Do you have password to save the file?", vbQuestion + vbYesNo)
If Ans = vbYes Then
Frm_Login.Show 'UserForm to accept the password
End If
Cancel = True
End Sub

snb
11-01-2020, 05:45 AM
Why disabling in the first place ?
When macros are designed properly it's fully redundant ( as is 'protection' in any form ).

rorobear
11-01-2020, 06:28 AM
because it's going to be a shared file and i don't want anyone making changes to it.

snb
11-01-2020, 10:56 AM
Then make it a read-only file.

rorobear
11-01-2020, 11:36 AM
i have tried that, but with ready-only the user can still save as under a different file name. i don't want the user to have any save capability.

snb
11-01-2020, 12:59 PM
the user can still save as under a different file name
So what ?

rorobear
11-01-2020, 02:47 PM
thanks for your help.

rorobear
11-01-2020, 03:37 PM
if anyone knows how to do it, i'd greatly appreciate the help.

Paul_Hossler
11-01-2020, 10:10 PM
Set an 'OK2Save' boolean variable

But the whole approach is not very secure

snb
11-02-2020, 01:57 AM
A user can always copy the contents of the file.

Paul_Hossler
11-02-2020, 08:15 AM
A user can always copy the contents of the file.


Oh, there's SO many ways to bypass it :think:

Jan Karel Pieterse
11-04-2020, 03:47 AM
If your company has Rights Management Service (RMS) setup you can prevent the user from doing all sorts of things depending on which templates have been set up for you (if any!):
27400
https://docs.microsoft.com/en-us/microsoft-365/enterprise/activate-rms-in-microsoft-365?view=o365-worldwide

rorobear
11-04-2020, 08:19 AM
I don't doubt it, but the people that will be viewing this workbook are not super excel savvy like you all. i'm not worried about anyone hacking or by passing the code. I just wanted to disable the basic save features, which this code seems to do. thank you again for the help and support. I appreciate your expertise.