Password to get access to certain sheet

  • Thread starter Thread starter Jonsson
  • Start date Start date
J

Jonsson

Hi,

I need a macro that asks for a password to get access to another sheet.
Lets say you have a button in sheet1 and when you click that button you get
access to sheet2, if you have the right password, otherwise you dont.

Thanks!

//Thomas
 
I need a macro that asks for a password to get access to another sheet.
Lets say you have a button in sheet1 and when you click that button you get
access to sheet2, if you have the right password, otherwise you dont.

This is doable with code such as follows. The insecurity is reprotecting
sheet2
when the user is done. The following assumes the password is in cell B10 of
sheet2. While it is "hidden" by making the font color match the cell
interior
color, it's easy for the user to find the password.

'sheet1 code
Private Sub CommandButton1_Click()
Dim ws As Worksheet
Set ws = Worksheets("sheet2")
ws.Unprotect
ws.Visible = xlSheetVisible
End Sub

'sheet2 code
Private Sub Worksheet_Deactivate()
Dim ws As Worksheet
Set ws = Worksheets("sheet2")
' reset password; hide by setting
' font to white (invisible)
ws.Range("B10").Font.ColorIndex = 2
ws.Protect ws.Range("B10")
ws.Visible = xlSheetHidden
End Sub

HTH,
Merjet
 

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