Is there a way that I can password protect a worksheet

L

Lin4it

Does anyone know if there is a way that I can password protect a worksheet
but still leave access to the rest of the workbook?
 
M

Mike H

Hi,

Alt +F11 to open VB editor. Double click 'This workbook' and paste the code
below in. This does what you want but isn't secure. If a user doesn't
enable macros they see the sheet. Anyone with even a small amount of
knowledge and Google would view your sheet in seconds. Change "Sheet1" to
whichever you want


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

Mike
 
M

Mike H

Missed a line, use this instead

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

End If
End If
Sheets(MySheet).Visible = True
End Sub

Mike
 
G

Gord Dibben

To just prevent editing on the sheet go to Tools>Protection>Protect sheet
with a password.

To prevent users from seeing the sheet....................

Format>Sheet>Hide

Tools>Protection>Protect Workbook with a password.

Note: Excel's internal security is very weak so be aware that a determined
user will be able to crack your password quite readily.


Gord Dibben MS Excel MVP
 

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