我知道Excel工作簿可以受密码保护。 有没有办法将 Excel 工作簿配置为在密码输入错误 3 倍后自毁或锁定进一步的尝试?
首先,
您必须通过转到以下操作在 excel 引用库中设置引用:
工具 ->引用 -> "Microsoft Visual Basic for Applications Extensibility 5.3"
(在VBA菜单中时)
接下来,您将修改代码,使其如下所示:
Sub DeleteModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim passwordAttempt As Int
passwordAttempt = 0
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ModuleName")
password = Application.InputBox("Enter Password", "Password Protected")
Select Case password
Case Is = False
'do nothing
Case Is = "easy"
'do something
Case Else
MsgBox "Incorrect Password"
passwordAttempt = passwordAttempt + 1
End Select
if passwordAttempt == 3 Then
VBProj.VBComponents.Remove VBComp
end if
End Sub
我不熟悉设置密码的正确语法,我只是将其用作参考。
如果您需要自删除部分的参考,可以查看此处。