Scruffymessiah
New Member
- Joined
- Sep 5, 2002
- Messages
- 45
I have been trying to unprotect a workbook by assigning the following to a button. The top code is for protecting the lower one for unprotecting. The top works and the bottom throws up errors. Can anyone help? I am new to VBA.
Sub Protect()
Dim theWord As String
theWord = InputBox("Please enter the password")
If theWord <> "lock" Then
MsgBox ("Sorry, you have entered the wrong password"), vbCritical
Exit Sub
End If
ActiveWorkbook.Protect Password:="lock", Structure:=True, Windows:=False
ActiveSheet.Protect Password:="lock", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub unprotect_sheets()
Dim theWord As String
theWord = InputBox("Please enter the password")
If theWord <> "unlock" Then
MsgBox ("Sorry, you have entered the wrong password"), vbCritical
Exit Sub
End If
ActiveWorkbook.unprotect_sheets Password:="unlock", Structure:=False, Windows:=True
ActiveSheet.unprotect_sheets Password:="unlock", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub Protect()
Dim theWord As String
theWord = InputBox("Please enter the password")
If theWord <> "lock" Then
MsgBox ("Sorry, you have entered the wrong password"), vbCritical
Exit Sub
End If
ActiveWorkbook.Protect Password:="lock", Structure:=True, Windows:=False
ActiveSheet.Protect Password:="lock", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Sub unprotect_sheets()
Dim theWord As String
theWord = InputBox("Please enter the password")
If theWord <> "unlock" Then
MsgBox ("Sorry, you have entered the wrong password"), vbCritical
Exit Sub
End If
ActiveWorkbook.unprotect_sheets Password:="unlock", Structure:=False, Windows:=True
ActiveSheet.unprotect_sheets Password:="unlock", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub