One way to do this is to put two CommandButtons on a sheet you're not going to hide.
Put these two codes to your buttons and it should work.
Note that the Input Box does not hide the letters you type.
Code:
Private Sub CommandButton1_Click()
'UNLOCK
Dim pass As String
pass = InputBox("Enter password:")
' If Cancel is pressed:
If StrPtr(pass) = 0 Then Exit Sub
' Correct password, unprotects the workbook and makes Sheet2 visible:
If pass = "password" Then
ThisWorkbook.Protect Password:="password", Structure:=False, Windows:=False
Sheets("Sheet2").Visible = True
MsgBox "Sheet is now visible"
Else
' Wrong password:
MsgBox "Wrong password"
Exit Sub
End If
End Sub
Private Sub CommandButton2_Click()
'LOCK
' Hides Sheet2 and protects the workbook so the _
sheet is not visible without password.
Sheets("Sheet2").Visible = xlVeryHidden
ThisWorkbook.Protect Password:="password", Structure:=True, Windows:=True
MsgBox "Sheet is now hidden"
End Sub
Another way (better imo) is to make your own userform. In that case you can also use password characters to hide what you're typing.