Macro that runs every minute when System Clock changes minute?

naira

New Member
Joined
May 7, 2013
Messages
16
Office Version
  1. 2013
Platform
  1. Windows
Hi!

I am looking for help to create a Macro that runs when system clock changes minute and then at every change of minute of system clock.

For example, if I give the execute command to start the macro at 09:14:45 (HH:MM:SS), then its first run should be only at 09:15:00, then next run at 09:16:00 so on...

I already have a Macro that runs every minute from initial run time, using
Code:
 Application.OnTime Now + TimeValue("00:01:00"), "MyMacro"
but it seems to be unreliable, because in case I open another sheet that takes lets say 20 seconds to open, the next macro run is delayed by 20 seconds.

Thanx
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi
See if this example is useful, adjust the times to your liking:

Code:
Sub EveryMinute()
Dim tsec$, i%, j%


Do
    tsec = Right(Time, 2)
    j = 0
    For i = 1 To 100
        j = j + 1       ' wait a little
    Next
Loop Until tsec = "00"      ' minute change
For i = 1 To 2
    
    Application.OnTime Now + TimeValue("00:00:30"), "Ramones"
 
Next


End Sub
 
Sub Ramones()
    Range("f" & Rows.Count).End(xlUp).Offset(1).Value = Time
    Application.Wait Now + TimeValue("00:00:20")
End Sub
 
Upvote 0
Hi Worf,
Thanx for your reply.
Tried your code but it goes into some sort of endless loop and excel hangs.

Also, Application.Wait would stop me from other things that I want to do during the 20 seconds wait. Can we avoid Application.wait?

Could you please check your code again and help me out?
 
Last edited:
Upvote 0
New version follows. Note that the macro will only return control to you when system clock changes minute, this does not mean hanging...

Code:
Sub EveryMinute()
Dim tsec$, i%, j%


Do
    tsec = Right(Time, 2)
    j = 0
    For i = 1 To 100
        j = j + 1       ' wait a little
    Next
Loop Until tsec = "00"      ' minute change


For i = 1 To 3          ' schedules three calls
    
    Application.OnTime Now + (TimeValue("00:00:20")) * i, "Ramones"
 
Next


End Sub
 
Sub Ramones()
    Range("f" & Rows.Count).End(xlUp).Offset(1).Value = Time
End Sub
 
Upvote 0
Rollis
Thanks for pointing it out.

Naira
I will not blacklist you, but please read the forum rules, specially Rule #10. The link is on my signature below.

We welcome your future posts...
 
Upvote 0
Upvote 0
Hi Naira</SPAN></SPAN>
Did you try the code on post #4? If it is not working, could you post your test macro?</SPAN></SPAN>
Also, if you get a final answer on other forum, please let us know.</SPAN></SPAN>
 
Upvote 0
Sorry for late reply guys, but after some extensive testing and some minor tweaking, it seems that the Solution suggested by jindon in post #18 at Macro that runs when System Clock changes minute? - Page 2 is the best available, since it only starts when the system clock minute changes and is also a one line solution.
Thanks a lot for all your help guys.
Thread solved.

PS: Another forum has an option to mark the thread as solved. Can we have the same option here too in the thread tools?
 
Last edited:
Upvote 0
Hi Naira
- To download that file at OzGrid one must be a member there. Could you post the solution here?

- I don't think this forum has the solved option enabled, and it would be nice; I suggest it at the thread title, like this:

[Solved] Help! How can I have Excel make me a cup of tea????
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top