ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protect Excel sheets with Password Using VBA (https://www.excelbanter.com/excel-programming/313610-protect-excel-sheets-password-using-vba.html)

Iain

Protect Excel sheets with Password Using VBA
 
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[_3_]

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


Iain

Protect Excel sheets with Password Using VBA
 
Thanks Dave - really appreciate the help.

"Dave Peterson" wrote:

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




All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com