ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Password Protection set for all worksheets (https://www.excelbanter.com/excel-programming/439035-password-protection-set-all-worksheets.html)

Craig

Password Protection set for all worksheets
 
Hi,

I need code to re-set the password on all my sheets within a workbook if the
user forgets to re-set it.

I am currently using a single 'ActiveSheet' code, but as I have added more
sheets need code to re-set on all sheets....my sheets do need to allow users
to input to unlocked cells.....am using this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveSheet.Protect Password:="MyPassword", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub

Thanks

Craig


Per Jessen[_2_]

Password Protection set for all worksheets
 
HI Craig
Try this one

Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each sh in ThisWorkbook.Sheets
sh.Protect Password:="MyPassword", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
Next
End Sub

Regards,
Per

On 31 Jan., 19:59, Craig wrote:
Hi,

I need code to re-set the password on all my sheets within a workbook if the
user forgets to re-set it.

I am currently using a single 'ActiveSheet' code, but as I have added more
sheets need code to re-set on all sheets....my sheets *do need to allow users
to input to unlocked cells.....am using this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveSheet.Protect Password:="MyPassword", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub

Thanks

Craig



Craig

Password Protection set for all worksheets
 
Yet again Per, first class code in such a quick time......Works perfectly

Many Thanks

Craig

"Per Jessen" wrote:

HI Craig
Try this one

Private Sub Workbook_BeforeClose(Cancel As Boolean)
For Each sh in ThisWorkbook.Sheets
sh.Protect Password:="MyPassword", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
Next
End Sub

Regards,
Per

On 31 Jan., 19:59, Craig wrote:
Hi,

I need code to re-set the password on all my sheets within a workbook if the
user forgets to re-set it.

I am currently using a single 'ActiveSheet' code, but as I have added more
sheets need code to re-set on all sheets....my sheets do need to allow users
to input to unlocked cells.....am using this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveSheet.Protect Password:="MyPassword", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
End Sub

Thanks

Craig


.



All times are GMT +1. The time now is 11:15 AM.

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