+ Reply to Thread
Results 1 to 6 of 6

Stop macro from executing multiple times with multiple clicks

  1. #1
    Registered User
    Join Date
    05-06-2020
    Location
    FL
    MS-Off Ver
    H&B 2016
    Posts
    14

    Stop macro from executing multiple times with multiple clicks

    Hello. I have a timer that I created for a specific purpose that is activated by a macro assigned button (shape). The problem that I am having is that if the button is clicked more than once while the timer is running the countdown time accelerates. In other words, the number of seconds that it takes off each cycle increases every time the button is clicked. The button sometimes will get clicked an extra time by mistake and I would like to prevent this from impacting the timer. How can I limit the macro from re-firing once it is already running? The code I am currently using is below. Note, there is a bit of noise in it because I actually have the timer running twice per cycle with different times and the times are assigned by cell references along with a delay between the two countdowns. That is why there are also macros with "2" at the end. The ones with no "2" at the end are specific to the first run and the ones with a "2" at the end are specific to the second run. I assume that some additional code will need to be added to the StartTimer macro to achieve what I want to do, but am not 100% sure, thus why I am sharing everything.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Stop macro from executing multiple times with multiple clicks


    Hi,

    from several obvious solutions one is to just hide the shape at the beginning of the procedure and unhide it at the end …

  3. #3
    Registered User
    Join Date
    05-06-2020
    Location
    FL
    MS-Off Ver
    H&B 2016
    Posts
    14

    Re: Stop macro from executing multiple times with multiple clicks

    Thank you for the quick reply Marc. That may work in some cases, but not in mine if it requires hiding columns or rows. If you are referencing hiding the shape itself, I am not familiar with how to do that.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Stop macro from executing multiple times with multiple clicks


    As I explicitly wrote « hide the shape » according to its property Visible, just taking a glance to its VBA help …

    Another obvious way is to declare a Static variable in the procedure and to check it in order to see if the procedure is already running …

  5. #5
    Registered User
    Join Date
    05-06-2020
    Location
    FL
    MS-Off Ver
    H&B 2016
    Posts
    14

    Re: Stop macro from executing multiple times with multiple clicks

    I am re-posting the code without 2 unnecessary marcos that I just noticed were still there. This may make it simpler to understand.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-06-2020
    Location
    FL
    MS-Off Ver
    H&B 2016
    Posts
    14

    Re: Stop macro from executing multiple times with multiple clicks

    Thank you Marc. I did not know that you could hide the shape, thus why I didn't associate your reply with explicitly hiding the shape. I will explore that further and see if that will work for me. I also like the idea of adding a static variable, so I will explore that more and decide which will work better for me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Executing Multiple queries in oracle using Macro
    By Kandavalli.Kiran in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2019, 03:16 PM
  2. multiple start/stop times in excel chart
    By jyoho107 in forum Excel Charting & Pivots
    Replies: 15
    Last Post: 09-12-2017, 02:55 PM
  3. Trying to run a macro multiple times
    By stevensmith867 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2013, 06:05 AM
  4. Macro for executing multiple sorting from a list
    By Bastard82 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2011, 10:20 AM
  5. Run Macro at multiple set times
    By dsrt16 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-17-2009, 11:36 AM
  6. Executing a Macro Across Multiple Worksheets
    By rdgreen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2008, 11:31 PM
  7. [SOLVED] Executing multiple queries through a macro
    By Sharon in forum Excel General
    Replies: 0
    Last Post: 03-31-2005, 09:06 PM

Tags for this Thread

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