+ Reply to Thread
Results 1 to 6 of 6

killing the macro

  1. #1
    Registered User
    Join Date
    08-30-2008
    Location
    London
    Posts
    35

    killing the macro

    Hi ive got a samll userform open whilst running a macro that takes a long time to process.
    Ive labelled a button on the form as "kill macro" and Id like to be able to stop processing completely if I press the button.

    I know I can use the keyboard to press CTRL+Break but it pops up an error and asks if I want to end. Is there a way to simulate the key press and automatically choose end to supress the message window?

    Thanks

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,440

    Re: killing the macro

    The way to do this is have a public boolean variable that you check every now and then, probably within your loops. If the variable is false you exit the looping and tidyup any processing you may be in the middle of.

    So before the looping starts you set the variable to TRUE.
    Within the loop you check for the variable being FALSE.

    And in the buttons click event you set the variable to FALSE.

    You will need a DoEvents command within you loop so the updating takes place.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    08-30-2008
    Location
    London
    Posts
    35

    Re: killing the macro

    Thanks Andy, im not sure how to incorporate it in the code. Can you help with breaking the loop and checking for the false. Im okay wth the object stuff but not very good with the loops.

    This is the code (you helped me adapt for the progress indicator)

    Please Login or Register  to view this content.
    Many Thanks
    Last edited by excel_lover; 08-21-2009 at 03:46 PM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,440

    Re: killing the macro

    userform with 2 buttons and a label

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-30-2008
    Location
    London
    Posts
    35

    Re: killing the macro

    Andy, thanks for your reply, ive managed to work it out. Ive hit a new problem though where the button is pressed and an error message

    Please Login or Register  to view this content.
    I always want to select end, is there a way to supress the message?

    Many Thanks

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,440

    Re: killing the macro

    can you post your workbook and explain what's needed in order to generate the error.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1