ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Store Passwords To Multiple Sheets and To Retain thatPasswords When the Workbook IS closed (https://www.excelbanter.com/excel-programming/438715-how-store-passwords-multiple-sheets-retain-thatpasswords-when-workbook-closed.html)

vicky

How to Store Passwords To Multiple Sheets and To Retain thatPasswords When the Workbook IS closed
 
i need a code to store password to multiple sheets and to retain that
passwords when i closed the workbook. according to my code it can
assigns a password but cannot retain the multiple passwords assigned
to multiple sheet .

Sub ProtectAll()

Pwd = InputBox("Enter your password to protect all worksheets")
If Pwd < "" Then
FormobjWSht_Input.Protect Password:=Pwd
Else
Exit Sub
End If

End Sub

Sub UnProtectAll()
'Dim Pwd As String

Pwd = InputBox("Enter your password to unprotect all worksheets",
"Password Input")
If Pwd < "" Then
On Error Resume Next
FormobjWSht_Input.Unprotect Password:=Pwd
If Err < 0 Then
MsgBox "You have entered an incorrect password. Worksheets could not "
& _
"be unprotected.", vbCritical, "Incorrect Password"
End If


John

How to Store Passwords To Multiple Sheets and To Retain that Passw
 
Vicky,
see if this does what you want.

Sub ProtectAll()
Dim sh As Worksheet
Dim Pwd As String

Pwd = InputBox("Enter your password to protect all worksheets")
If Pwd < "" Then

For Each sh In ActiveWorkbook.Worksheets

sh.Protect Password:=Pwd

Next sh

Else

Exit Sub

End If

End Sub

Sub UnProtectAll()
Dim sh As Worksheet
Dim Pwd As String

Pwd = InputBox("Enter your password to unprotect all worksheets",
"Password Input")

If Pwd < "" Then

On Error GoTo myerror

For Each sh In ActiveWorkbook.Worksheets

sh.Unprotect Password:=Pwd

Next sh

myerror:
If Err 0 Then

MsgBox "You have entered an incorrect password. Worksheets could
not " _
& "be unprotected.", vbCritical, "Incorrect Password"

Err.Clear

End If

End If

End Sub

--
jb


"vicky" wrote:

i need a code to store password to multiple sheets and to retain that
passwords when i closed the workbook. according to my code it can
assigns a password but cannot retain the multiple passwords assigned
to multiple sheet .

Sub ProtectAll()

Pwd = InputBox("Enter your password to protect all worksheets")
If Pwd < "" Then
FormobjWSht_Input.Protect Password:=Pwd
Else
Exit Sub
End If

End Sub

Sub UnProtectAll()
'Dim Pwd As String

Pwd = InputBox("Enter your password to unprotect all worksheets",
"Password Input")
If Pwd < "" Then
On Error Resume Next
FormobjWSht_Input.Unprotect Password:=Pwd
If Err < 0 Then
MsgBox "You have entered an incorrect password. Worksheets could not "
& _
"be unprotected.", vbCritical, "Incorrect Password"
End If

.



All times are GMT +1. The time now is 05:43 PM.

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