繁体   English   中英

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

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

Excel中是否有一种内置方法来仅使用密码保护工作簿中的一个电子表格?

当用户在控件上打勾或选择一个控件时,会在工作表可见之前提示输入密码。

如果它不是Excel内置的,可以用VBA实施吗?

您可以尝试以下方法:

  • 使工作表VeryHidden和“ Protected ,以使其无法从标准xl菜单中受到保护(或无法检测到)
  • Workbook_BeforeCloseWorkbook_Open事件上重新添加此保护
  • 在此示例中,我使用了名为YourSheet的工作表
  • 您还应该在此项目中保护VBA,以增加安全性。

插入一个Active X复选框并使用代码检查是否:

  1. 复选框为True
  2. 用户知道UnHide表的密码。 (在此示例中使用了Fred

复选框代码

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

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