View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default password protect a sheet

Joe,

Alt+F11 to open VB editor, double click 'This Workbook' and paste the code
below in on the right. Change the name of the worksheet to the one you want
to protect.

You should be aware that there is no foolproof way of doing this and that
this method is a deterrent only.


Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ws = ("Sheet2")
If ActiveSheet.Name = (ws) Then
ActiveSheet.Visible = False
response = InputBox("Enter password")
If response = "MyPass" Then
Sheets(ws).Visible = True
Application.EnableEvents = False
Sheets(ws).Activate
Application.EnableEvents = True
Else
MsgBox "Your not allowed to see that sheet"
Sheets(ws).Visible = True
End If
End If
End Sub


Mike


"Joe" wrote:

Is there a way to prevent someone from viewing a worksheet. I know that I
can hide the worksheet and then password protect the workbook to prevent the
user from unhiding the sheet. I would prefer to still see the tabs but not
allow anyone to view that worksheet.