View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Password Protect Unhide Worksheet?

Hi,

There is no real secure way of doing this in Excel but this should deter the
average user.

Alt+F11 to open VB editor. Double ckick 'ThisWorkbook' and paste the code
below in on the right. Change mysheet to the name of the sheet you want to
protect.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
mysheet = "Sheet1"
If ActiveSheet.Name = mysheet Then
Application.EnableEvents = False
ActiveSheet.Visible = False
response = InputBox("Enter password to view sheet")
If response = "MyPass" Then
Sheets(mysheet).Visible = True
Sheets(mysheet).Select
End If
End If
Sheets(mysheet).Visible = True
Application.EnableEvents = True
End Sub

Mike


"garyh" wrote:

Is there a way to password protect a worksheet so that the user cannot UNHIDE
the worksheet unless she/he knows the password?

Thanks, in advance, for your help.

G