Reputation: 1251
Is there a built-in way in Excel to protect just one spreadsheet in a Workbook with a Password?
Something like when user ticks or selects a Control , a password is prompted before a Worksheet become visible.
If its not built into Excel, can it be implemented with VBA?
Upvotes: 1
Views: 1036
Reputation: 55692
You could try this approach which:
VeryHidden
and Protected
so that it can't be unprotected - or detected - from the standard xl menusWorkbook_BeforeClose
and Workbook_Open
eventsInsert an Active X
checkbox and use code to check if:
UnHide
the sheet. (Fred is used in this example)CheckBox code
Private Sub CheckBox1_Click()
Dim StrPass As String
If CheckBox1.Value Then
StrPass = Application.InputBox("Please enter the password", "Admin check")
If StrPass = "fred" Then
With ThisWorkbook.Sheets("YourSheet")
.Unprotect "fred"
.Visible = xlSheetVisible
MsgBox "Sheet unhidden!", vbInformation
End With
Else
MsgBox "wrong password", vbCritical
End If
End If
End Sub
the ThisWorkbook
module
Private Sub Workbook_BeforeClose(Cancel As Boolean)
With ThisWorkbook.Sheets("YourSheet")
.Protect "fred"
.Visible = xlVeryHidden
End With
End Sub
Private Sub Workbook_Open()
With ThisWorkbook.Sheets("YourSheet")
.Protect "fred"
.Visible = xlVeryHidden
End With
End Sub
Upvotes: 2