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.
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.