Implementing Cancels in VBA Loops

Posted on Tuesday 21 October 2008

I like to allow users the opportunity to cancel out of long loops if they need to. I use a global variable, something like gbCanacel, which gets set to True when the user clicks the Cancel button.

CancelButton.PNG

Then my looping checks for this with an if statement, normally the last thing inside the next/loop statement. If it detects that gbCancel is True, then I reset gbCancel and exit the sub. With liberal use of DoEvents this works quite well.

If you implement Cancel, do you do it the same way. If not how and why!!!!


5 Comments for 'Implementing Cancels in VBA Loops'

  1.  
    JP
    21 October 2008 | 9:50 pm
     

    What kind of form is that where the end user can click the cancel button while you’re in the middle of a VBA routine? My assumption was that while code is running, buttons are disabled. More detail please.

    –JP

  2.  
    22 October 2008 | 12:02 pm
     

    Ross
    Yep same approach, opposite logic (if bContinue? at the top)

  3.  
    22 October 2008 | 10:38 pm
     

    well one of us must be backwards then!

  4.  
    6 January 2009 | 12:17 am
     

    Zoo sex….

    Zoo sex. Animals sex zoo. Free zoo sex. Sex and the spotted hyena national zoo fonz….

  5.  
    6 January 2009 | 10:11 am
     

    Acyclovir….

    Acyclovir picture. Usage of acyclovir for ramsay hunt syndrome. Acyclovir seizures. Acyclovir….

Leave a comment

(required)

(required)


.

Use [VBA] Your Code [/VBA], when posting code, cheers Ross x /


RSS feed for comments on this post | TrackBack URI