fdesorme
03-26-2009, 05:45 AM
I'm new to VBA programming and am trying to get a simple worksheet protection macro working but am having problems with getting the password set using data from an inputbox. The procedure protects the worksheet, but I cannot unprotect the worksheet within excel when using the same password. Here is the code:
Sub ProtectSheet()
Dim Pswd As String
Pswd = InputBox("Please enter the password.", "Password entry")
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Protect Password:="& Pswd &", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
Next WS
End Sub
Thanks
Sub ProtectSheet()
Dim Pswd As String
Pswd = InputBox("Please enter the password.", "Password entry")
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Protect Password:="& Pswd &", DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True
Next WS
End Sub
Thanks