Skip to main content

How to set password to protect hidden sheet in Excel?

If you have a workbook which contains some important hidden worksheets, and do not allow others to unhide them. Now, you need to set a password to protect the hidden worksheets completely, when other users unhide them, they must enter the password. Do you have any ways to deal with this task quickly and easily in Excel?

Set password to protect hidden sheets with VeryHidden function

Set password to protect hidden sheet with VBA code

Protect multiple worksheets at once with Kutools for Excel


Set password to protect hidden sheets with VeryHidden function

Normally, you can use the VeryHidden function to hide the worksheets first, and then set a password for them, please do as following steps:

1. Open your workbook, and hold Alt + F11keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click View > Project Explorer and Properties Window to display their panes.

doc-protect-hidden-sheets-01

3. And then in the Project-VBAProject pane, choose the worksheet that you want to hide, and in the Properties pane, click the drop down list from the Visible section to select xlSheetVeryHidden option, see screenshot:

doc-protect-hidden-sheets-02

4. After making the worksheet veryhidden, you can set a password to protect it. In the Microsoft Visual Basic for Applications window, click Insert > Module to open an empty module, and then click Tools > VBAProject Properties, see screenshot:

doc-protect-hidden-sheets-03

5. Then in the popped out VBAProject-Project Properties dialog box, click Protection tab, and then check Lock project for viewing box, finally, enter and confirm the password in the Password to view project properties section, see screenshot:

doc-protect-hidden-sheets-04

6. Then click OK button to exit this dialog, and close the Microsoft Visual Basic for Applications window.

7. Save the workbook as Excel Macro-Enabled Workbook format and close it to make the password protection take effect.

doc-protect-hidden-sheets-05

8. Next time, when you open this workbook, and want to make the veryhidden sheets be visible, you are requested to enter a password. See screenshot:

doc-protect-hidden-sheets-06


Demo: Set password to protect hidden sheets


Set password to protect hidden sheet with VBA code

To set a password to protect the hidden sheets, I can also talk about a VBA code for you.

1. Hide one worksheet that you want to protect.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Then choose ThisWorkbook from the left Project Explorer, double click it to open the Module, and then copy and paste following VBA code into the blank Module:

VBA code: Set password to protect hidden sheet

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
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

doc-protect-hidden-sheets-07

Note: In the above code, Sheet1 of the xSheetName = "Sheet1" script is the hidden worksheet name that you want to protect, and 123456 in the If response = "123456" Then script is the password that you set for the hidden sheet. You can change them to your need.

4. Now, when you want to show the hidden sheet, a prompt box will pop out to let you enter the password. And this prompt box will appear each time, when you click to show the hidden sheet.

doc-protect-hidden-sheets-08


Protect multiple worksheets at once with Kutools for Excel

If you want to protect multiple selected or all worksheets of a workbook at once, normally, you need to protect one by one manually in Excel. But, if you have Kutools for Excel, with its Protect Worksheet utility, you can protect them with one click.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days

After installing Kutools for Excel, please do as follows:

1. Click Kutools Plus > Protect Worksheet, see screenshot:

2. In the Protect Worksheet dialog box, all worksheets within the workbook are listed into the list box, please choose the worksheets that you want to protect. See screenshot:

doc-protect-hidden-sheets-010

3. And then click OK, in the following dialog box, please enter your password and retype it again, then click OK, another prompt box will pop out to remind you how many worksheets have been protected.

doc-protect-hidden-sheets-011

4. Then click OK to close the dialogs, and all of the worksheets in the workbook have been protected with the same password.

Note: If you want to unprotect all of the worksheets at once, you just need to click Kutools Plus > Unprotect Worksheet, and type your password to cancel the protection.

 Download and free trial Kutools for Excel Now !


Related articles:

How to protect multiple worksheets at once in Excel?

How to set a password to protect the workbook?

How to protect / lock VBA code in Excel?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
jak ktoś ukrył arkusz jak w opisanym pierwszym sposobie, a nie znamy hasła to jak odkryć arkusz skoro hasło do visual basic jest w ukrytym arkuszu?
This comment was minimized by the moderator on the site
Hello, ciekawa

Sorry, at present, there is no good way for canceling the protect of the hidden sheet if you forget the password.

But, you can apply the Uhide all hidden sheets feature of Kutools for Excel to unhide all the hidden sheets without any password.
https://www.extendoffice.com/images/stories/comments/comment-skyyang/doc-unhide-sheets.png
You can download Kutools for Excel and use it freely for 30 days.
Please have a try. Thank you!
This comment was minimized by the moderator on the site
This is elegant. IF the person opening the spreadsheet does not enable macros (i.e. VBA) what happens? Is the hidden sheet a sitting duck? Or is it quite impossible to find?
This comment was minimized by the moderator on the site
Hi, David,
If you open the workbook without enabling the macro, the hidden sheet is displayed as normal. In this case, I recommend you to apply the first method for solving this job.
Thank you!
This comment was minimized by the moderator on the site
Your code allows users to view the sheet as long as they hold the left mouse button while the mouse pointer is on the tab. Try this to keep sheet hidden until correct password is entered: If response = "123456" Then Application.Sheets(xSheetName).Visible = True Application.Sheets(xSheetName).Select Else Application.Sheets(xSheetName).Visible = False[/b][/b] End If End If Application.EnableEvents = True End Sub
This comment was minimized by the moderator on the site
I have a question about your password restricted worksheet code. You posted the following code which works....what I am looking for is code that will do this with multiple worksheets and multiple passwords within the same workbook. Is this possible? 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 comment was minimized by the moderator on the site
Found a solution yet?

I am having the same problem
This comment was minimized by the moderator on the site
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim aSheetName As String
Dim bSheetName As String
Dim cSheetName As String
aSheetName = "sheet1"
bSheetName = "sheet2"
cSheetName = "sheet3"

If Application.ActiveSheet.Name = aSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "123" Then
Application.Sheets(aSheetName).Visible = True
Application.Sheets(aSheetName).Select
Else
Application.Sheets(aSheetName).Visible = False
End If
End If
Application.EnableEvents = True

If Application.ActiveSheet.Name = bSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "456" Then
Application.Sheets(bSheetName).Visible = True
Application.Sheets(bSheetName).Select
Else
Application.Sheets(bSheetName).Visible = False
End If
End If
Application.EnableEvents = True

If Application.ActiveSheet.Name = cSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "789" Then
Application.Sheets(cSheetName).Visible = True
Application.Sheets(cSheetName).Select
Else
Application.Sheets(cSheetName).Visible = False
End If
End If
Application.EnableEvents = True

End Sub
This comment was minimized by the moderator on the site
Thanks for the code, just have one question. When you open the sheet you are asked for question, then you enter it and the sheet is visible, but when you jump to next sheet and try to re-open previous sheet, you are asked for the same password again everytime. My question is can you bypass that and make excel ask for password once?
This comment was minimized by the moderator on the site
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim xSheetName As String
aSheetName = "sheet1"
bSheetName = "sheet2"
cSheetName = "sheet3"

If Application.ActiveSheet.Name = aSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "1234" Then
Application.Sheets(aSheetName).Visible = True
Application.Sheets(aSheetName).Select
Else
Application.Sheets(aSheetName).Visible = False
End If
End If
Application.EnableEvents = True

If Application.ActiveSheet.Name = bSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "2345" Then
Application.Sheets(bSheetName).Visible = True
Application.Sheets(bSheetName).Select
Else
Application.Sheets(bSheetName).Visible = False
End If
End If
Application.EnableEvents = True

If Application.ActiveSheet.Name = cSheetName Then
Application.EnableEvents = False
Application.ActiveSheet.Visible = False
xTitleId = "KutoolsforExcel"
response = Application.InputBox("Password", xTitleId, "", Type:=2)
If response = "3456" Then
Application.Sheets(cSheetName).Visible = True
Application.Sheets(cSheetName).Select
Else
Application.Sheets(cSheetName).Visible = False
End If
End If
Application.EnableEvents = True

End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations