Protecting a workbook

K

Kim

Hi,
I have no problem protecting a worksheet with the 'Protect Sheet' option,
but is there anyway i can protect the whole workbook the same way, without
having to select each sheet individually?
Thanks in advanced!
 
O

Otto Moehrbach

Kim
When you click on Tools - Protection, you have the option of protecting
the whole workbook. HTH Otto
 
S

Spiky

You may wish to note, Kim, that Protect Workbook does different things
than Protect Sheet. If you are wanting to protect many sheets at a
time, you'll need a macro.
 
T

tech1NJ

Hi Kim,

You can create a macro to take care of this. As part of the Macro, you will
create a Form with a Command Button. You can then add the code to the
Commnand button as follows.

Private Sub CommandButton1_Click()
Dim wSheet As Worksheet
For Each wSheet In Worksheets
If wSheet.ProtectContents = True Then

wSheet.Unprotect Password:=TextBox1.Text
Else
wSheet.Protect Password:="replace this text with password you wish
to open sheets with"
End If
Next wSheet
Unload Me
End Sub
 
G

Gord Dibben

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

Unprotect all sheets....................

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

Protect selected sheets..........................

Sub Protect_Selected_Sheets()
Application.ScreenUpdating = False
Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets
ws.Select
ws.Protect Password:="justme"
Next ws
Application.ScreenUpdating = True
End Sub

Unprotect selected sheets................

Sub UnProtect_Selected_Sheets()
Application.ScreenUpdating = False
Set MySheets = ActiveWindow.SelectedSheets
For Each ws In MySheets
ws.Select
ws.UnProtect Password:="justme"
Next ws
Application.ScreenUpdating = True
End Sub


Gord Dibben MS Excel MVP
 
T

tech1NJ

Hi Kim,

Did you find my post useful? Please let me know. I like to make sure that
you got what you needed. If so, please let me know by indicating so on the
reply or the post itself. Thanks
 

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