Tuesday, September 18, 2012

How to check whether Cancel has been pressed in the InputBox.

This is a method to identify that the cancel button has been pressed in the InputBox.
InputBox returns vbNullString if the cancel button is clicked.
If the string is vbNullString, StrPtr will be 0.

Sub main()
    Dim sTemp As String
    sTemp = InputBox("What's the value?")
    If StrPtr(sTemp) = 0 Then
        MsgBox "Cancel was clicked"
    End If
End Sub

No comments: