
Cancel button doesn't end macro
Actually, my problem wasn't with it exiting (more on that to come), it was
how to identify that the InputBox "Cancel" button had been clicked and end
the sub on that click. What was happening was that the sub continued to run
even after "Cancel" had been clicked. I didn't run very long though. I
discovered that the routine always got exited regardless of the InputBox
response because the value of vbCancel is always "2". That made the If
statement always true so the sub always exited. Reading further in the help
files I found that hitting "Cancel" returns a zero length string. I was
able to check for that value in a Do While...Loop to solve the problem.
Brian
Quote:
> Hi Brian,
> When I test your code, the routine exits the sub without a problem.
> However, if you have a call stack and this routine is only one of the
> routines in the call stack, then the Exit Sub statement will not end the
> entire call stack. If this is what you're trying to accomplish, then use
> "End"
> HTH
> > Why doesn't the "Cancel" button in an InputBox end the macro? If it's
not
> > supposed to, how do I end the macro if it's been pressed? I've tried
> > checking the return value of vbCancel but now the macro is ended
> regardless
> > of the InpuBox response. What am I doing wrong?
> > Here's the last piece of code that I tried.
> > vResponse = InputBox(vMessage, vTitle, vDefault)
> > If vbCancel = 2 Then
> > MsgBox "Operation cancelled!"
> > Exit Sub
> > End If