ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Password to get access to certain sheet (https://www.excelbanter.com/excel-programming/287462-password-get-access-certain-sheet.html)

Jonsson

Password to get access to certain sheet
 
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



merjet

Password to get access to certain sheet
 
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





All times are GMT +1. The time now is 02:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com