Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

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


Protect multiple or all worksheets at once:

With Kutools for Excel’s Protect Worksheet and Unprotect Worksheet, you can protect or unprotect all worksheets within a workbook with the same password at once.

doc-protect-multiple-sheets-9

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!


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 60 days

After installing Kutools for Excel, please do as follows:

1. Click Enterprise > Protect Worksheet, see screenshot:

doc-protect-hidden-sheets-09

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 Enterprise > Unprotect Worksheet, and type your password to cancel the protection.

doc-protect-hidden-sheets-012

 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?


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 80% Excel problems.

  • Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  • Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  • Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  • Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  • No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  • Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  • 60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  • Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
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.
    Jeremy · 2 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 · 2 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 · 1 years ago
      Found a solution yet?

      I am having the same problem
      • To post as a guest, your comment is unpublished.
        Richard · 1 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 · 11 months 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 · 1 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