I want to protect and unprotect multiple sheets except 3 sheets in ky workbook named "pvt1" , "pvt2" , "pvt3" and also with this same code i want to protect active workbook. with vba
Currently using this macro
VBA TO PROTECT .
Sub ProtectAll()
'
' PROTECTALL Macro
'
ActiveWorkbook.Protect
top:
pass = InputBox("password?")
repass = InputBox("Verify Password")
If Not (pass = repass) Then
MsgBox "you made a boo boo"
GoTo top
End If
For i = 1 To Worksheets.Count
If Worksheets(i).ProtectContents = True Then GoTo oops
Next
For Each s In ActiveWorkbook.Worksheets
s.Protect Password:=pass
Next
Exit Sub
oops: MsgBox "I think you have some sheets that are already protected. Please unprotect all sheets then running this Macro."
End Sub
VBA TO UNPROTECT
Sub UnProtectAll()
'
' Unprotectall Macro
'
ActiveWorkbook.Unprotect
Dim ws As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to unprotect all worksheets", "Unprotect Worksheets")
On Error Resume Next
For Each ws In Worksheets
ws.Unprotect Password:=Pwd
Next ws
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
End Sub
Currently using this macro
VBA TO PROTECT .
Sub ProtectAll()
'
' PROTECTALL Macro
'
ActiveWorkbook.Protect
top:
pass = InputBox("password?")
repass = InputBox("Verify Password")
If Not (pass = repass) Then
MsgBox "you made a boo boo"
GoTo top
End If
For i = 1 To Worksheets.Count
If Worksheets(i).ProtectContents = True Then GoTo oops
Next
For Each s In ActiveWorkbook.Worksheets
s.Protect Password:=pass
Next
Exit Sub
oops: MsgBox "I think you have some sheets that are already protected. Please unprotect all sheets then running this Macro."
End Sub
VBA TO UNPROTECT
Sub UnProtectAll()
'
' Unprotectall Macro
'
ActiveWorkbook.Unprotect
Dim ws As Worksheet
Dim Pwd As String
Pwd = InputBox("Enter your password to unprotect all worksheets", "Unprotect Worksheets")
On Error Resume Next
For Each ws In Worksheets
ws.Unprotect Password:=Pwd
Next ws
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error GoTo 0
End Sub