jrfarmer2010
New Member
- Joined
- Jan 18, 2018
- Messages
- 8
Hey there, I'm hoping for some help with my VBA code in Excel 2016. First, I know that this is not fool-proof security, but that's fine for what I'm working with. I have an excel workbook, with many hidden sheets (one for each employee), and a menu tab with buttons linking to each sheet. I have VBA code on each sheet requiring a password, but when I click the button from the menu tab, it pulls up and shows the sheet with a password box on top of it. Is there a way to hide the content of the sheet until after the password is entered? I'm not sure if this should be part of the button or the sheet code, so I've posted both below. Thanks for any help!
Here is my button code
and here is my sheet code
Here is my button code
Code:
Sub GSG_Target_Employee()
Sheets("Menu").Select
Sheets("Stellar Employee").Visible = True
Sheets("Stellar Employee").Select
End Sub
and here is my sheet code
Code:
Private Sub Worksheet_Activate()
Dim strPassword As String
On Error Resume Next
Me.Protect Password:="Test"
Me.Columns.Hidden = True
strPassword = InputBox("Enter password to access worksheet. Please contact FirstName LastName for assistance")
If strPassword = "" Then
Me.Columns.Hidden = True
Worksheets("Menu").Select
Exit Sub
ElseIf strPassword <> "Test" Then
MsgBox "The password you entered is not correct"
Me.Columns.Hidden = True
Worksheets("Menu").Select
Exit Sub
Else
Me.Unprotect Password:="Test"
Me.Columns.Hidden = False
End If
Range("a1").Select
On Error GoTo 0
End Sub