Password Protection set for all worksheets

C

Craig

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
 
P

Per Jessen

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
 
C

Craig

Yet again Per, first class code in such a quick time......Works perfectly

Many Thanks

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top