Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
InputBox Function & Cancel Otto Moehrbach[_6_] Excel Programming 4 September 30th 04 01:13 AM
Help with inputbox (Distinguish OK from Cancel) NooK[_47_] Excel Programming 3 August 5th 04 11:45 AM
Clicking Cancel on an Inputbox rott[_6_] Excel Programming 3 March 5th 04 02:57 AM
Inputbox and cancel button Uddinj1 Excel Programming 5 March 2nd 04 11:27 AM
Cancel button in Inputbox method MiRa Excel Programming 2 November 14th 03 01:04 PM


All times are GMT +1. The time now is 04:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"