Just wondering if anyone has created a vba code to emulate the 'Protect/Unprotect Workbook' icon yet?
Just need the same function (or similar) to that icon, but with vba.
Thank you!
Just wondering if anyone has created a vba code to emulate the 'Protect/Unprotect Workbook' icon yet?
Just need the same function (or similar) to that icon, but with vba.
Thank you!
Excelerate
Revised answer following user clarifiication...
I don't know XLS Padlock (nor do iI have time to try it) but it seems it has VBA security setting which might prevent this working...
Suggest you save the attached file which has two simple macros below in Module1 (and buttons on Sheet1):
Public Pwd As String, Conf As String
Sub ProtectFile()
UserForm1.Show
If Pwd <> "" Then
UserForm2.Show
End If
If Pwd = Conf Then ActiveWorkbook.Protect Structure:=True, Windows:=False, Password:=Pwd
MsgBox "Structure protected"
End Sub
Sub UnprotectFile()
Pwd = InputBox("Enter the password", "Protect workbook structure")
ActiveWorkbook.Unprotect Password:=Pwd
MsgBox "File unprotected"
End Sub
Two public variables are declared (Pwd and Conf) and the Protect sub uses two UserForms to collect them, password and confirmation password. The key thing here is that the text entered in the UserForms is masked using the PasswordChar property of the TextBox (here I used an asterisk *).
I've just used a simple InputBox (unmasked) in the Unprotect sub and leave you to use a UserForm instead if you like.
If they work, great. If not perhaps someone else will answer who knows XLS Padlock (are you sure that XLS Padlock does not have options to protect your file structure?).
Hope this helps
ActiveWorkbook.Protect Structure:=True, Windows:=False
ActiveWorkbook.Unprotect
UserForm2.Show
Sub UnprotectFile()
On Error Resume Next
Pwd = InputBox("Enter the password", "Protect workbook structure")
ActiveWorkbook.Unprotect Password:=Pwd
If Err.Number = 1004 Then
MsgBox "Password does not match!"
Else
MsgBox "File unprotected"
End If
End Sub
Sub ProtectFile()
'Reset confirming pwd, in case there's a password,
Conf = ""