PDA

View Full Version : [SOLVED:] Worksheet Protection



jmenche
02-05-2007, 10:02 AM
Howdy,

Is there a way to protect one sheet in a workbook so that the user has to supply a password to view it? This sounds like a custom routine would need to be written.

:beerchug:

OBP
02-05-2007, 10:36 AM
jmenche, yes you can, but you also need the code for resetting the Protection afterwards. You can just record a Macro of doing this yourself to get the code. You can also go in to the Visual Basic Editor and look at it's "Help" which is completely different from the ordinary Excel help.
If you search for "Protect Method" and "Unprotect Method", it shows examples.

lucas
02-05-2007, 10:48 AM
one password for all or one password for each user?

CBrine
02-05-2007, 12:01 PM
This code added to the ThisWorkbook level of the vbe will allow you to force a password on a sheet select. The only problem is that you see that data for a quck second on the initial switch. The password and Sheet3 will need to be replaced with your strings.



Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim password As String
If Sh.Name = "Sheet3" Then
Sh.Visible = False
If InputBox("Please enter sheet view password") <> "password" Then
MsgBox "Incorrect Password"
Application.EnableEvents = False
Sh.Previous.Select
Application.EnableEvents = True
Sh.Visible = True
Else
Sh.Visible = True
Application.EnableEvents = False
Sh.Activate
Application.EnableEvents = True
End If
End If
End Sub


HTH
Cal

jmenche
02-05-2007, 01:08 PM
CBrine,

Thanks. That works fine!