Article ID: 142111
Article Last Modified on 10/11/2006
Sub Protect_Example1()
' Loop through all sheets in the workbook.
For i = 1 To Sheets.Count
Sheets(i).Protect
Next i
End Sub
This example prompts you to determine if you want to protect the current
sheet. If you answer yes, the sheet is then protected with a hard-coded
password.
Sub Protect_Example2()
' Loop through all sheets in the workbook
For i = 1 To Sheets.Count
' Activate each sheet in turn.
Sheets(i).Activate
response = MsgBox("Do you want to protect this sheet?", vbYesNo)
If response = vbYes Then
ActiveSheet.Protect password:="larry", DrawingObjects:=True, _
Contents:=True, Scenarios:=True
ElseIf response = vbNo Then
MsgBox ("Sheet not protected")
End If
Next i
End Sub
For i = 1 To Worksheets.Count
Worksheets(i).Activate
To protect only module sheets:
For i = 1 To Modules.Count
Modules(i).Activate
To protect only chart sheets:
For i = 1 To Charts.Count
Charts(i).Activate
To protect only Dialog sheets:
For i = 1 To DialogSheets.Count
DialogSheets(i).Activate
Additional query words: 8.00 XL
Keywords: kbdtacode kbhowto KB142111