Password protect hidden sheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am attempting to create a spreadsheet where one of the sheets is hidden
until clicking a button. The part I can't figure out is I would like it to be
password protected (when you click the button you are prompted for a
password). Does anyone have any recommendations?
My reason for this is only a select number users are supposed to be able to
see this second sheet, but no it is not top secret so if somebody were to
somehow bypass it, it would not be the end of the world.
Thanks!
Luke
 
If you make it very hidden, the user would have to use code to unhide it. It
cannot be unhidden from the menu. See xlVeryHidden in the VBA help files.
 
Hi Luke -

Here's some draft code to assign to your button's click event. Modify to
suit:

Private Sub CommandButton1_Click()
pwd = "secret"
i_pwd = InputBox("Please Enter Password to Unhide Sheet", "Unhide Sheet...")
Select Case i_pwd
Case pwd
Worksheets("Luke'sSheetNameHere").Visible = True
Case Else
MsgBox "Incorrect password; no action taken.", vbInformation,
"Unhide Sheet..."
End Select
End Sub

Note that users could find the password by entering visual basic and reading
your code. To minimize this possibility, lock the project against viewing
as follows:

In the VB Editor Project Explorer window:

1. Right-click the name of the project and choose 'VBAProject Properties...'.

2. Click the 'Protection' Tab and check the box 'Lock project for viewing'.

3. Enter a password and confirm it. Click [OK] to finish.

4. The VB code will be unviewable the next time you open it (after you save
and close the file).
 
Thanks to both of you- that is exactly what I needed and I would have never
figured it out on my own!
 
Jay,

Would this work for multiple sheets? I have 10 worksheets. Only one person
can access one worksheet, but not the other 9 worksheets.

Jay said:
Hi Luke -

Here's some draft code to assign to your button's click event. Modify to
suit:

Private Sub CommandButton1_Click()
pwd = "secret"
i_pwd = InputBox("Please Enter Password to Unhide Sheet", "Unhide Sheet...")
Select Case i_pwd
Case pwd
Worksheets("Luke'sSheetNameHere").Visible = True
Case Else
MsgBox "Incorrect password; no action taken.", vbInformation,
"Unhide Sheet..."
End Select
End Sub

Note that users could find the password by entering visual basic and reading
your code. To minimize this possibility, lock the project against viewing
as follows:

In the VB Editor Project Explorer window:

1. Right-click the name of the project and choose 'VBAProject Properties...'.

2. Click the 'Protection' Tab and check the box 'Lock project for viewing'.

3. Enter a password and confirm it. Click [OK] to finish.

4. The VB code will be unviewable the next time you open it (after you save
and close the file).

----
Jay


Luke said:
I am attempting to create a spreadsheet where one of the sheets is hidden
until clicking a button. The part I can't figure out is I would like it to be
password protected (when you click the button you are prompted for a
password). Does anyone have any recommendations?
My reason for this is only a select number users are supposed to be able to
see this second sheet, but no it is not top secret so if somebody were to
somehow bypass it, it would not be the end of the world.
Thanks!
Luke
 

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

Back
Top