ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unprotecting Several Sheets At Once (https://www.excelbanter.com/excel-programming/421173-re-unprotecting-several-sheets-once.html)

Zee[_2_]

Unprotecting Several Sheets At Once
 
I have some code entered in to protect all the sheets upon close however I
would like to be able to unprotect them all by only entering the password
once as it is the same for all the sheets.

Thanks

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True


End Sub



Gord Dibben

Unprotecting Several Sheets At Once
 
Sub unprotectall()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).UnProtect Password:="password"
Next N
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP


On Thu, 11 Dec 2008 09:52:00 -0800, Zee
wrote:

I have some code entered in to protect all the sheets upon close however I
would like to be able to unprotect them all by only entering the password
once as it is the same for all the sheets.

Thanks

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True


End Sub



ryguy7272

Unprotecting Several Sheets At Once
 
From Excel's help menu:
ActiveWorkbook.Unprotect

Modify your macro accordingly...

Regards,
Ryan---

--
RyGuy


"Zee" wrote:

I have some code entered in to protect all the sheets upon close however I
would like to be able to unprotect them all by only entering the password
once as it is the same for all the sheets.

Thanks

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True


End Sub



Tom Hutchins

Unprotecting Several Sheets At Once
 
You can use code very similar to the code you use to protect the sheets:

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single, pwd
pwd = InputBox("Enter password")
If Len(pwd) = 0 Then Exit Sub
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:=pwd
Next N
Application.ScreenUpdating = True
End Sub

Hope this helps,

Hutch

"Zee" wrote:

I have some code entered in to protect all the sheets upon close however I
would like to be able to unprotect them all by only entering the password
once as it is the same for all the sheets.

Thanks

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Protect Password:="password"
Next N
Application.ScreenUpdating = True


End Sub




All times are GMT +1. The time now is 10:02 AM.

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