How to password protect several excel workbook pages using a macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I can write a macro to protect lots of pages in a big workbook, but they are
protected without a password. How can I password protect them? I use Excel
2000.
 
In Help, look up the syntax for the Protect method of the worksheet. (In the
immediate window, type protect, then press F1.) Help has everything you want
to know.
 
Assume by "pages" you mean "worksheets".

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

Sub UnprotectAllSheets()
Application.ScreenUpdating = False
Dim N As Single
For N = 1 To Sheets.Count
Sheets(N).Unprotect Password:="justme"
Next N
Application.ScreenUpdating = True
End Sub

Gord Dibben Excel MVP
 

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

Back
Top