If the cancel button is clicked then InputBox returns a zero length string, so just check on that. For example,
x = InputBox("Input Something")
If x = "" Then Exit Sub
Yes, but you could perhaps get around this by having a default entry for each input box of " " (a space) and then after you checked for the cancel button you could check for the space and remove it or do whatever you would normally do with a blank entry.
Try to use like this:
text=inputbox("type the text")
if StrPtr(text)=0 then
'if it entenrs here then the user pressed "cancel"
'if enters here the user left in blank
'if enters here the user entered some text
excellent use of the strptr function there. Might I offer that a Select Case could tidy the code somewhat
VB:Dim response As Variant response = InputBox("Prompt", "Title") Select Case StrPtr(response) Case 0 'OK not pressed Exit Sub Case Else 'OK pressed 'Carry on your routine, variable response contains the InputText End Select
Please do not post your question in threads started by others - - this is known as thread hijacking.
Always start a new thread for *YOUR* question. If you find it helpful to clarify your needs you can include a link to this ( or any other ) thread.
When starting a new thread be sure to give it a search-friendly title that aptly describes your need.
The better your title define the thread the more relevant the results returned when searching.
There are currently 3 users browsing this thread. (1 members and 2 guests)