How to handle cancel when using the inputbox method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I handle the return from a CANCEL button that is clicked on when the
inputbox method is present. As far as I can tell there is nothing available
to test on. The Inputbox Function is not an option. Thanks in advance.
 
Is this what you want?

Dim rslt As Variant
rslt = Application.InputBox("Enter Stuff")
If rslt = False Then
MsgBox "Cancelled"
Else
MsgBox rslt
End If


Hope this helps
Rowan
 
Try this:

Sub test()

Dim strTemp As String

strTemp = InputBox("testing the Cancel button")

If StrPtr(strTemp) = 0 Then
MsgBox "Cancel was pressed"
Else
MsgBox "OK was pressed"
End If

End Sub


RBS
 
If you enter a zero and do OK it will be a Cancel.
I think using StrPtr is the only way.

RBS
 
I have just been reading up on StrPtr following your post - it's a new
one for me. Thanks.

Regards
Rowan
 
Hello Lawood,

Just for reference, the InputBox method returns a boolean False when
Cancel is pressed and the InputBox function returns an empty string.

Sincerely,
Leith Ross
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top