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:
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.
Find Error Line Number in VBA With Erl
In this post you are going to find out a way of handling errors in your code with the Erl function. Erl displays the last label before the error Another alternative error handling solution is using labels at each point in long procedure. Here we get a random error: Here is the code behind the […]
Here Is A Customized Msgbox VBA Example
Here is an example of a customized VBA Msgbox. We giving some richtext and customizable flair to the rather ordinary message box. The following code provided with the code after the screenshot, is going to provide you with the ability to really make the ordinary message box shine! Sub MsgboxVBAExamples() Dialog.Box “VBAHowTo.com is your source […]
How To Use A Variable In A VBA Message Box.
In this post I’m going to show you how to use a variable in a vba message box. This is used commonly to notify the user that an entered item in a combo box is not in the list, also per this post it’s to display the error number or the error description to the […]
How To Make A VBA Msgbox Yes No
You can use a VBA Msgbox Yes No to get guidance from the user an the control your program’s flow In the following example I am asking the user to confirm whether or not they want to continue. I am storing the answer in the integer variable intAnswer, and then my algorithm processes their answer […]