Article ID: 193649
Article Last Modified on 10/10/2006
Sub Protect_Example1()
Dim i As Integer
' 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()
Dim response As Integer
Dim i as Integer
' 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
176476 OFF: Office Assistant Not Answering Visual Basic Questions
Additional query words: XL98
Keywords: kbdtacode kbhowto KB193649