This'll protect all the unprotected worksheets with the same password:
Option Explicit
Sub testme01()
Dim myPwd As String
Dim wks As Worksheet
myPwd = InputBox(prompt:="what's the password, kenny?")
If Trim(myPwd) = "" Then
Exit Sub
End If
For Each wks In ThisWorkbook.Worksheets
If wks.ProtectContents _
Or wks.ProtectDrawingObjects _
Or wks.ProtectScenarios Then
'already protected
Else
wks.Protect Password:=myPwd
End If
Next wks
This'll protect all the unprotected worksheets with the same password:
Option Explicit
Sub testme01()
Dim myPwd As String
Dim wks As Worksheet
myPwd = InputBox(prompt:="what's the password, kenny?")
If Trim(myPwd) = "" Then
Exit Sub
End If
For Each wks In ThisWorkbook.Worksheets
If wks.ProtectContents _
Or wks.ProtectDrawingObjects _
Or wks.ProtectScenarios Then
'already protected
Else
wks.Protect Password:=myPwd
End If
Next wks
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.