0

I have a timer within Excel VBA code which did run smooth untill 6 weeks ago. Please see the code below. I use this timer in a workbook. I use 2 identical copies of this workbook (with different names). I run these 2 workbooks in 2 separate instances of Excel (using Windows11-button > Run > excel /x > Enter) on my workstation. Next I run the code below in both workbooks. This always functioned perfectly: updating the clock every second in cell K1.

Since 6 weeks ago the code skips a few seconds now and then: jumping from 20:15:00 to 20:15:07 for example instead of 20:15:01. This happens specifically if I run 2 workbooks. Running 1 workbook is still running smooth.

Sub UPDATECLOCK()

ThisWorkbook.Sheets(1).Range("K1") = Time

NextTick = Now + TimeValue("00:00:01")

Application.OnTime NextTick, "UPDATECLOCK"

End Sub


Sub StopClock()

On Error Resume Next
Application.OnTime NextTick, "updateclock", , False

Stop


End Sub

My workstation has enough cores and memory to do this simple task. I have also reinstalled an image from 6 months ago. I have updated Office 365. I have switched Personal and Business Office 365. Although I do not succeed to solve the issue.

Any idea what can be the cause and solution for this issue?

Thanks a lot!

6
  • 1
    Your machine is busy doing something else at that moment. Probably something that wasn't clashing until 6 weeks ago. The OnTime command adds a request to run no sooner than 1 second later, but there are no guarantees it'll fire at that moment. Excel is not set up to take that kind of priority over your machine. Commented Jun 17 at 10:38
  • @CLR Thank you. I did also test it on another machine resulting in the same issue. In the task manager the CPU is at 1%. Can there be something specific clashing with Excel? Commented Jun 17 at 17:40
  • 2
    Using the timer in such a way is very usually the indication of a wrong approach in general. What exactly you are trying to achieve? Commented Jun 17 at 22:59
  • You may want to review stackoverflow.com/q/79580185/3688861 Commented Jun 18 at 0:01
  • @Tragamor Thank you. That is a very interesting link. I will check this and post the outcome. Commented Jun 18 at 7:47

1 Answer 1

-1

Try copy/paste your macro into Notepad. Then copy your code from Notepad and paste it into a clean, new workbook - not previously used for anything. Now run that version of the macro and see what occurs.

For what it is worth, I ran your macro here without any issues. Runs fine.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, I have tried, although this does not solve my issue. Are you using Office 365 on Windows as I do?
ps: and sorry for downvoating your answer. I can't undo. I ment it was no solution for my issue, although it is a good answer.
Running Excel 2007 on Win 11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.