+ Reply to Thread
Results 1 to 9 of 9

Vba code to cancel a timer

  1. #1
    Registered User
    Join Date
    07-15-2021
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    Vba code to cancel a timer

    Hi,

    I have a worksheet with a pop up macro, now i need the code to stop the macro.

    my sheet has 10 rows (each row for a different contractor), so when a contractor calls me i enter his details and start the macro by clicking a button, when i run the macro my Msgbox appears every hour, i would now like to know how to create a macro to stop the Msgbox appearing. i am using the code below but it doesnt work.

    Please Login or Register  to view this content.
    thanks in advance
    Attached Files Attached Files
    Last edited by 6StringJazzer; 07-25-2021 at 08:09 PM. Reason: please use CODE tags; made title more specific

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Vba code to cancel a timer

    You have code to stop the timer in two different places. Let's just use the one in Module1 and ignore the one in Module2.

    The call to stop the timer must have the time that the timer is set for. You are using interval for this, but the variable interval is never declared and never set, so it's going to be 0. I strongly recommend to everyone that they use Option Explicit and declare variables. Doing so prevents a lot of bugs, like this one.

    You are starting the timer to expire in 10 seconds. This does not match your description of 1 hour, so I'm not clear on what you are trying to do.

    There is the potential to start multiple timers. So to cancel any of them, you have to store the time someplace for each one. I am going to suggest you do this in column AK. However, that also means you have to determine which row is affected when the timer button is clicked.

    I get an error on the call to LockCells. That is because you are using merged cells. Merged cells are almost always a bad idea that will cause problems, especially with VBA. I fixed the code but I strongly suggest you redesign so you don't need merged cells.

    I only updated the buttons in the first row. You will have to set all Start buttons to call My_Macro and all Complete buttons to call stop_macro.

    I suspect that after you get the timer issue settled you will see other problems. Post back to this same thread when that happens.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Vba code to cancel a timer

    Hi there,

    See if the following version of your code does what you need:

    Please Login or Register  to view this content.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  4. #4
    Registered User
    Join Date
    07-15-2021
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    Re: Vba code to cancel a timer

    Hi Jeff,

    i had the timer set to 10 secs as i was trying to test it instead of waiting an hour, and the merged cells dont need to be merged, i was trying something else with that earlier, but thank you for your help, i will look at again tomorrow and let you know how i get on, again thank you so much

    Ed

  5. #5
    Registered User
    Join Date
    07-15-2021
    Location
    London
    MS-Off Ver
    2016
    Posts
    4

    Re: Vba code to cancel a timer

    Hi Greg,

    Thank you for your reply, ill have another look at this tomorrow, and let you know how i get on, thanks again.

    Ed

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Vba code to cancel a timer

    @GReg M this was my initial thought as well but this method will not work because there could be multiple timers active at one time, so the solution must keep track of multiple EarliestTime values.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Vba code to cancel a timer

    Hi Jeff,

    You're quite right!

    It was late at night when I looked at this post so I concentrated only on the VBA code aspects. It was only when I saw your post (after I'd posted mine) that I realised how much more was involved.

    Best regards,

    Greg M

  8. #8
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,220

    Re: Vba code to cancel a timer

    You should also remember to stop all active counters when we close the file(but Excel still remains open). Otherwise, the file will be opened at the specified time and the OnTime event will be dispatched. OnTime is "remembered" at the application level, not at the workbook level.

    Artik

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Vba code to cancel a timer

    Attached a different approach to timing - each channel has its own 'ticker' so they do not interact/interfere with each other
    Use for split work timing (solicitor/accountant) - some of the coding methodology I have used maybe useful.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

+ 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. [SOLVED] Need to edit an Excel macro but can't stop the Workbook_Open code running
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2019, 05:35 AM
  2. [SOLVED] VBA Code to stop macro going any further if certain cells have data in them
    By Stevec63 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-21-2018, 06:34 PM
  3. [SOLVED] Macro Code Will Not Stop Saving In My Module
    By TBM in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-12-2016, 01:22 PM
  4. Help in macro code to stop code running for certain time
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-05-2015, 02:35 AM
  5. [SOLVED] How to stop a code from running using an another code/macro
    By danjim02 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2013, 08:21 AM
  6. [SOLVED] VBA code to stop the macro
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-25-2013, 02:17 PM
  7. Code to stop a worksheet_selectionchange macro running
    By hriggs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-17-2009, 06:23 AM

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