1

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

就像用户勾选或选择 Control 时,会在 Worksheet 可见之前提示输入密码。

如果它没有内置在 Excel 中,可以用 VBA 实现吗?

4

1 回答 1

2

您可以尝试以下方法:

  • 制作工作表VeryHiddenProtected使其无法从标准 xl 菜单中不受保护或检测到
  • Workbook_BeforeClose在和Workbook_Open事件上重新添加此保护
  • 在这个例子中,我使用了一张名为YourSheet的工作表
  • 您还应该保护此项目中的 VBA 以增加安全性。

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

  1. 复选框为真
  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
于 2013-04-09T02:43:47.857 回答