password protect a sheet

J

Joe

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.
 
M

Mike H

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
 
S

ShaneDevenshire

Hi,

You can choose Format, Cells, Protection and turn on Hidden. Then you can
select the range you don't want the user to view and change its Number format
to the custom format ;;; and then reprotect the spreadsheet.
 
G

Gord Dibben

Not sure why you want to see a sheet tab but not the contents but......

You could format all cells to locked and hidden under
Format>Cells>Protection.

Then Format all cells to white text.

Protect the sheet and not allow users to select locked or unlocked cells or
anything else.

Note: Excel internal security is very weak and passwords easily cracked.


Gord Dibben MS Excel MVP
 
J

Joe

Thanks, I'll try this.

Mike H said:
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
 
G

Gord Dibben

And how will that allow you to see the sheet tab but not the contents as
your original post required?


Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top