Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
InputBox - cancel button
Hi,
how do you detect if the user presses 'Cancel' on an InputBox? - i want to exit sub if this button is pressed Many thanks in advance Greg |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
InputBox - cancel button
response = MsgBox ("Question", vbOKCancel) If response = vbCancel then End Sub End If -- Zurn ------------------------------------------------------------------------ Zurn's Profile: http://www.excelforum.com/member.php...o&userid=14645 View this thread: http://www.excelforum.com/showthread...hreadid=268119 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
InputBox - cancel button
sorry, the End Sub has to be Exit Sub ;) -- Zurn ------------------------------------------------------------------------ Zurn's Profile: http://www.excelforum.com/member.php...o&userid=14645 View this thread: http://www.excelforum.com/showthread...hreadid=268119 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
InputBox - cancel button
Cancel returns an empty string.
Dim ans as String ans = InputBox("entry please") if ans = "" then Msgbox "Response not acceptable, exiting" exit sub End if The user could hit OK without making an entry and this would be interpreted as a cancel. If you want to differentiate, then Sub TestInput() Dim ans As String ans = InputBox("Response:") If StrPtr(ans) = 0 Then MsgBox "You hit cancel" Exit Sub ElseIf ans = "" Then MsgBox "You hit OK with no entry" Exit Sub Else MsgBox "Your answer is " & ans End If End Sub -- Regards, Tom Ogilvy "Greg Billinge" wrote in message ... Hi, how do you detect if the user presses 'Cancel' on an InputBox? - i want to exit sub if this button is pressed Many thanks in advance Greg |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
InputBox - cancel button
Greg, the InputBox function will return a blank string ("") if Cancel is clicked.
Sub testCancel() stest = InputBox("Press Cancel to see what is returned") If stest = "" Then MsgBox "You pressed Cancel" Else MsgBox "You didn't press Cancel." End If End Sub "Greg Billinge" wrote in message ... Hi, how do you detect if the user presses 'Cancel' on an InputBox? - i want to exit sub if this button is pressed Many thanks in advance Greg |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
InputBox Function & Cancel | Excel Programming | |||
Help with inputbox (Distinguish OK from Cancel) | Excel Programming | |||
Clicking Cancel on an Inputbox | Excel Programming | |||
Inputbox and cancel button | Excel Programming | |||
Cancel button in Inputbox method | Excel Programming |