Sub ProtectAll()
Dim S As Object
Dim stocks As Worksheet
Dim pWord1 As String, pWord2 As String
Dim answer As Integer
Dim OutPut1, OutPut2 As Integer
answer = MsgBox("Protect this workbook?", vbYesNo + vbQuestion)
If answer = vbNo Then Exit Sub Else
pWord1 = InputBox("Please enter the password")
If pWord1 = "" Then Exit Sub
pWord2 = InputBox("Please re-enter the password")
If pWord2 = "" Then Exit Sub
If InStr(1, pWord2, pWord1, 0) = 0 Or _
InStr(1, pWord1, pWord2, 0) = 0 Then
OutPut1 = MsgBox(" You entered different passwords." & vbCrLf & " No action taken!", vbExclamation, "Error!")
Exit Sub
End If
Application.ScreenUpdating = False
Range("E1,G1,I1,K1,M1").Select
Selection.EntireColumn.Hidden = True
Range("N1").Select
Sheets("data").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("stocks").Select
Application.ScreenUpdating = True
For Each ws In Worksheets
ws.Protect Password:=pWord1
Next
OutPut2 = MsgBox("Workbook is protected!", vbInformation)
Exit Sub
End Sub