Re: Macros to Protect/Unprotect Worksheets and Workbooks
VB:
Code
Dim ws As Worksheet
Sub ProtectAll()
Dim S As Object
Dim pWord1 As String, pWord2 As String
pWord1 = InputBox("Please Enter the password")
If pWord1 = "" Then Exit Sub
pWord2 = InputBox("Please re-enter the password")
If pWord2 = "" Then Exit Sub
'make certain passwords are identical
If InStr(1, pWord2, pWord1, 0) = 0 Or _
InStr(1, pWord1, pWord2, 0) = 0 Then
MsgBox "You entered different passwords. No action taken"
Exit Sub
End If
For Each ws In Worksheets
ws.Protect Password:=pWord1
Sheets("Sheet2").Unprotect Password:=pWord1
Next
MsgBox "All sheets Protected."
Exit Sub
End Sub
Display More
I need a revise code for these current code that i posted, since i cannot work into it..
my problem is, everytime i put a password on the protectall, it overwrites the previous password i already put it in.
for example, i put 12345 password for the first time and it did protect the whole sheet, but when i try to input another password for example 67890, it overwrites the 12345??
thanks for the help..