View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mike Fogleman[_2_] Mike Fogleman[_2_] is offline
external usenet poster
 
Posts: 206
Default Protecting multiple sheets

Robert, Excel is not going to give you the password entered into it's
built-in dialog box to re-use for each sheet. The simplest method is to use
an inputbox to get the password like the following code:

Sub protect()
Dim w As Worksheet
Dim pwd As String
pwd = InputBox("Password", "Password Protect All Sheets")
For Each w In Worksheets
w.protect Password:=pwd
Next
End Sub

If you need to provide the protection options, rather than just full
protection, as the above code does, then you would need to build your own
userform similar to what the built-in has, and write code for each option. A
lot of extra work.

Mike F
"Robert Crandal" wrote in message
...
If my workbook has 20 sheets, I would like to write a script
that protects all 20 sheets at once, but it only asks the user
for a password once. I basically want to display the same
dialog box that appears when someone presses the "Protect Sheet"
button.

Is this possible?