My macro —which sets a timer— stops running when I open other windows.

Miguelcb

New Member
Joined
Jun 4, 2023
Messages
1
Office Version
  1. 365
Platform
  1. MacOS
Hi all, I have created a timer in Excel —MacOS— using a Macro with the following code:

Sub timer()
Worksheets("Timer").Range("A16").Value = Worksheets("Timer").Range("A16").Value - TimeValue("00:00:01")
interval = Now + TimeValue("00:00:01")
Application.OnTime interval, "timer"
If Worksheets("Timer").Range("A16").Value = 0 Then
Application.OnTime EarliestTime:=interval, Procedure:="timer", Schedule:=False
Beep
VBA.Interaction.MsgBox "Time!", , "Timer"
Worksheets("Timer").Range("A16").Value = "00:20:00"
Dim countCell As Range
Set countCell = Worksheets("Timer").Range("A20")
countCell = countCell + 1
Exit Sub
End If
End
Sub

This code works fine as long as my main active window is the Workbook that runs the macro. However, when I open a new window (it can be a Word document or Mozilla Firefox), the macro stops running —and, therefore, the timer stops.

Does anyone have a solution to keep my macro running even when I open other windows?

I appreciate any help you can provide.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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