How do I hide a worksheet in Excel and use a password to un-hide .

J

Jason Morin

To hide:

Sub Hide_Ws()
Sheets("Sheet1").Visible = xlSheetVeryHidden
End Sub

-------------

To unhide:

Sub Unhide_Ws()

Dim psword As String

psword = InputBox("Enter password to unhide worksheet.")
If psword = "" Then Exit Sub
If psword = "1234" Then
Sheets("Sheet1").Visible = True
Else
MsgBox "Incorrect password."
End If
End Sub

---
Note that when hiding the worksheet sheet, it sets it
at "veryhidden", meaning that it cannot be unhidden from
the Format menu. Password is currently set to "1234".

HTH
Jason
Atlanta, GA
 
A

Arvi Laanemets

Hi

Additionally, you have to protect the VBA-project with password too -
otherwise the user can activate VBA editor and change worksheets Visible
propertie manually back to xlSheetVisible witout any password.
 
Top