View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
keithl816
 
Posts: n/a
Default restricting access to a worksheet?


How about require a user to enter a password.

This code will hide/unhide a sheet as needed. When you click on the
button it will prompt you for a password then open if correct, when you
click it again it will rehide the sheet.

Add a command button to a sheet and then right click it, click on view
code and place this code into it. Make sure to change the command
button name/number as needed and also change the sheet name/number
accordingly. just make sure to password protect the VBA Project in the
VBE so that the user cannot look at the code for the password.


Code:
--------------------

Private Sub CommandButton1_Click()
If Sheet1.Visible = xlSheetVisible Then
Sheet1.Visible = xlSheetVeryHidden
sCap = "Unhide " & Sheet1.name
Else
sPW = Application.InputBox("YOU ARE ATTEMPTING TO OPEN A CONFIDENTIAL FORM, ADMINISTRATIVE RIGHTS ARE REQUIRED, YOU MUST ENTER A PASSWORD TO OPEN THIS DOCUMENT")
If sPW = "password" Then
Sheet1.Visible = xlSheetVisible
sCap = "Hide " & Sheet1.name
Else
MsgBox "Incorrect Password"
sCap = "Unhide Sheet1"
End If
End If
End Sub
--------------------


Hope this will help.

Larry


--
keithl816
------------------------------------------------------------------------
keithl816's Profile: http://www.excelforum.com/member.php...o&userid=21287
View this thread: http://www.excelforum.com/showthread...hreadid=530211