View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_3_] Dave Peterson[_3_] is offline
external usenet poster
 
Posts: 2,824
Default Protect Excel sheets with Password Using VBA

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

End Sub

Iain wrote:

Is there a way to prompt for a password that covers all sheets when using VBA
to protect multiple sheets in a workbook?


--

Dave Peterson