Need code to protect worksheets - amount of worksheets varies

S

Sandy

Hello!

I need code that will protect worksheets and the
workbook. There are many workbooks involved and depending
on the particular workbook, it will have X amount of
worksheets in it with various names.

Also, I need to hide certain sheets in each workbook -
those will always be the same.

Any suggestions will be greatly appreciated!

Sandy
 
G

Guest

heres a macro that i use all the time

this protects all the sheets and the workbook


Sub protect()

Dim i As Integer
' Loop through all sheets in the workbook.
' change this for the number of sheets
For i = 1 To Sheets.Count
Sheets(i).protect "PASSWORD", True, True, True
'Range("A1").Select
Next i
'protect workbook
ActiveWorkbook.protect Structure:=True, Windows:=False
ActiveWorkbook.protect "PASSWORD", True, False
End Sub


Sub unprotect()


Dim i As Integer
' Loop through all sheets in the workbook.
' this can also be set to a number
For i = 1 To Sheets.Count
Sheets(i).unprotect "PASSWORD"
'Range("A1").Select
Next i
ActiveWorkbook.unprotect "PASSWORD"
End Sub


hope this helps

kevin
 

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