ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple Worksheets - Protection (https://www.excelbanter.com/excel-programming/384867-multiple-worksheets-protection.html)

Josh O.

Multiple Worksheets - Protection
 
What is the most best way, with a macro, to Protect all worksheets in a
workbook using a popup asking for a password, and specify what functions a
users can use? And then to unlock it also, with a popup asking for the
password.

For example, I want to protect all the worksheets and have users be able to
"Select Unlocked Cells", "Select Locked Cells", and "Format Cells".

Also, to unprotect all the worksheets with a macro that pops up asking for
the password to unprotect all the sheets.

I hope that makes sense.

Jim Thomlinson

Multiple Worksheets - Protection
 
This should be close...

Sub ProtectAll()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

For Each wks In Worksheets
wks.EnableSelection = xlNoRestrictions
wks.Protect Password:=strPassword, _
Contents:=True, _
AllowFormattingCells:=True
Next wks
End Sub

Sub UnProtectAll()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

On Error Resume Next
For Each wks In Worksheets
wks.Unprotect Password:=strPassword
Next wks
On Error GoTo 0
End Sub
--
HTH...

Jim Thomlinson


"Josh O." wrote:

What is the most best way, with a macro, to Protect all worksheets in a
workbook using a popup asking for a password, and specify what functions a
users can use? And then to unlock it also, with a popup asking for the
password.

For example, I want to protect all the worksheets and have users be able to
"Select Unlocked Cells", "Select Locked Cells", and "Format Cells".

Also, to unprotect all the worksheets with a macro that pops up asking for
the password to unprotect all the sheets.

I hope that makes sense.


Josh O.

Multiple Worksheets - Protection
 
Thanks Jim.

"Jim Thomlinson" wrote:

This should be close...

Sub ProtectAll()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

For Each wks In Worksheets
wks.EnableSelection = xlNoRestrictions
wks.Protect Password:=strPassword, _
Contents:=True, _
AllowFormattingCells:=True
Next wks
End Sub

Sub UnProtectAll()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

On Error Resume Next
For Each wks In Worksheets
wks.Unprotect Password:=strPassword
Next wks
On Error GoTo 0
End Sub
--
HTH...

Jim Thomlinson


"Josh O." wrote:

What is the most best way, with a macro, to Protect all worksheets in a
workbook using a popup asking for a password, and specify what functions a
users can use? And then to unlock it also, with a popup asking for the
password.

For example, I want to protect all the worksheets and have users be able to
"Select Unlocked Cells", "Select Locked Cells", and "Format Cells".

Also, to unprotect all the worksheets with a macro that pops up asking for
the password to unprotect all the sheets.

I hope that makes sense.


Jim Thomlinson

Multiple Worksheets - Protection
 
Here is a link to some code to remove passwords for the case when someone can
not rememeber the password that they added...

http://www.mcgimpsey.com/excel/removepwords.html
--
HTH...

Jim Thomlinson


"Josh O." wrote:

Thanks Jim.

"Jim Thomlinson" wrote:

This should be close...

Sub ProtectAll()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

For Each wks In Worksheets
wks.EnableSelection = xlNoRestrictions
wks.Protect Password:=strPassword, _
Contents:=True, _
AllowFormattingCells:=True
Next wks
End Sub

Sub UnProtectAll()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

On Error Resume Next
For Each wks In Worksheets
wks.Unprotect Password:=strPassword
Next wks
On Error GoTo 0
End Sub
--
HTH...

Jim Thomlinson


"Josh O." wrote:

What is the most best way, with a macro, to Protect all worksheets in a
workbook using a popup asking for a password, and specify what functions a
users can use? And then to unlock it also, with a popup asking for the
password.

For example, I want to protect all the worksheets and have users be able to
"Select Unlocked Cells", "Select Locked Cells", and "Format Cells".

Also, to unprotect all the worksheets with a macro that pops up asking for
the password to unprotect all the sheets.

I hope that makes sense.



All times are GMT +1. The time now is 03:39 PM.

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