简体   繁体   English

使用密码保护一个工作表不显示

[英]Protect one worksheet with a password from showing up

Is there a built-in way in Excel to protect just one spreadsheet in a Workbook with a Password? Excel中是否有一种内置方法来仅使用密码保护工作簿中的一个电子表格?

Something like when user ticks or selects a Control , a password is prompted before a Worksheet become visible. 当用户在控件上打勾或选择一个控件时,会在工作表可见之前提示输入密码。

If its not built into Excel, can it be implemented with VBA? 如果它不是Excel内置的,可以用VBA实施吗?

You could try this approach which: 您可以尝试以下方法:

  • Makes the sheet VeryHidden and Protected so that it can't be unprotected - or detected - from the standard xl menus 使工作表VeryHidden和“ Protected ,以使其无法从标准xl菜单中受到保护(或无法检测到)
  • Adds back in this protection on the Workbook_BeforeClose and Workbook_Open events Workbook_BeforeCloseWorkbook_Open事件上重新添加此保护
  • I haved used a sheet called YourSheet for this example 在此示例中,我使用了名为YourSheet的工作表
  • You should protect the VBA in this project as well to add further security. 您还应该在此项目中保护VBA,以增加安全性。

Insert an Active X checkbox and use code to check if: 插入一个Active X复选框并使用代码检查是否:

  1. The checkbox is True 复选框为True
  2. The user knows the password to UnHide the sheet. 用户知道UnHide表的密码。 ( Fred is used in this example) (在此示例中使用了Fred

CheckBox code 复选框代码

Private Sub CheckBox1_Click()
    Dim StrPass As String
    If CheckBox1.Value Then
        StrPass = Application.InputBox("Please enter the password", "Admin check")
        If StrPass = "fred" Then
            With ThisWorkbook.Sheets("YourSheet")
                .Unprotect "fred"
                .Visible = xlSheetVisible
                MsgBox "Sheet unhidden!", vbInformation
            End With
        Else
            MsgBox "wrong password", vbCritical
        End If
    End If
End Sub

the ThisWorkbook module ThisWorkbook模块

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    With ThisWorkbook.Sheets("YourSheet")
        .Protect "fred"
        .Visible = xlVeryHidden
    End With
End Sub

Private Sub Workbook_Open()
    With ThisWorkbook.Sheets("YourSheet")
        .Protect "fred"
        .Visible = xlVeryHidden
    End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM