Reputation: 1205
I'm coding a macro where in the main menu there's a button to access the "Admin" worksheet where one can make important changes. I want only certain users to access this Admin worksheet, and I wonder if there's a way to password-protect viewing a worksheet, not just modifying it.
Upvotes: 0
Views: 1579
Reputation: 606
You could do something like this:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Update 20140925
Dim xSheetName As String
xSheetName = "Sheet1"
If Application.ActiveSheet.Name = xSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "123456" Then
Application.Sheets(xSheetName).Visible = True
Application.Sheets(xSheetName).Select
End If
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End Sub
This will in effect create a password protected worksheet that will only be visible if the supplied password is correct. This answer came from http://www.extendoffice.com/documents/excel/2134-excel-password-protect-hidden-sheet.html#a1
Upvotes: 3