2015-09-16 92 views
0

我想知道如何在運行宏之前使用密碼保護按鈕?如何用密碼保護按鈕?

我試了下面的代碼,它工作的很好,但我不能在第三次輸入密碼的情況下退出。

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 
+2

用戶可以打開宏和讀取密碼。 – SLaks

回答

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 
+0

非常感謝您的幫助:) –