I would like to know how to code for vbCancel in an InputBox. I have tried If..Then's but keep getting bugged out of the routine. Any help would be appreciated. Thanks.
Glenn
I would like to know how to code for vbCancel in an InputBox. I have tried If..Then's but keep getting bugged out of the routine. Any help would be appreciated. Thanks.
Glenn
Good morning Glenn
You don't actually need vbCancel, but if the cancel button is clicked the value of the input box is returned to VBA as false. Yes, I know it departs from the usual rules, but that's VBA for you - and I don't think it's actually documented in the help files. Try this code;
Sub Example()
YourName = Application.InputBox("Please enter your name", _
"Enter Your Name", "Name", 100, 100, , , 2)
If YourName = False Then Exit Sub
MsgBox "Your name is " & YourName
End Sub
HTH
DominicB
Hello Dominic
Youdaman! This has been driving me crazy because I knew VBA was absolutely perfect and I was the idiot. I'm still an idiot but a little less thanks to you.
Thanks very much.
Glenn
Hi Glenn
You're welcome. And thank you for the feedback.
DominicB
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks