This post will demonstrate how you can use the VBA input box cancel button to
exit the sub procedure.
When you click the “Cancel” button on the input box, you return a null (blank) value, and
knowing this information, you can exit the sub procedure.
Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 Sub VBAInputBoxCancel()
Dim strResponse As String
strResponse = InputBox("Enter the Password To Continue", "Enter Credentials")
'A clicked 'Cancel' button will result in a blank value
If strResponse = "" Then
MsgBox "You clicked the cancel button", vbInformation, "Bye"
Exit Sub
Else
Select Case strResponse
Case "Proc33d"
MsgBox "Thank you"
Case Else
MsgBox "Wrong Password"
Exit Sub
End Select
End If
End Sub
Any questions? We would love to hear your comment (s) below.