我想知道如何在运行宏之前用密码保护按钮?
我尝试了以下代码,效果很好,但是如果第三次密码不正确,我就无法退出。
strPassword = "HR"
For lTries = 1 To 3
strPassTry = InputBox("Enter Password please", "RUN MACRO")
If strPassTry = vbNullString Then
Exit Sub
End If
bSuccess = strPassword = strPassTry
If bSuccess = True Then Exit For
MsgBox "Password incorrect"
Next lTries
答案 0 :(得分:0)
@SLaks评论旁边......
strPassword = "HR"
For lTries = 1 To 3
strPassTry = InputBox("Enter Password please", "RUN MACRO")
If strPassTry = vbNullString Then
Exit Sub
End If
bSuccess = strPassword = strPassTry
If bSuccess Then Exit For
MsgBox "Password incorrect"
Next lTries
If Not bSuccess Then
Msgbox "Wrong password supplied!"
Exit Sub
End If