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?


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

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!
officetab bottom
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    David · 11 months ago
    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?
    • To post as a guest, your comment is unpublished.
      skyyang · 8 months ago
      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!
  • To post as a guest, your comment is unpublished.
    Jeremy · 3 years ago
    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
  • To post as a guest, your comment is unpublished.
    Darren · 3 years ago
    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
    • To post as a guest, your comment is unpublished.
      Severin · 2 years ago
      Found a solution yet?

      I am having the same problem
      • To post as a guest, your comment is unpublished.
        Rexamillian · 2 years ago
        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
        • To post as a guest, your comment is unpublished.
          Tomas · 2 years ago
          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?
      • To post as a guest, your comment is unpublished.
        Rexamillian · 2 years ago
        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