Martina Hawkins
New Member
- Joined
- Aug 24, 2018
- Messages
- 2
Hi, I have a stopwatch which is working great except when a user opens a new workbook the undo function is unavailable. It becomes available again when the clock is stopped.
I have the code below in a module. Does this happen to anyone else?
Option Explicit
Dim NextTick As Date, t As Date, PreviousTimerValue As Date
Private Sub StartTime()
PreviousTimerValue = Calculations.Range("A1").Value
t = Time
Call ExcelStopWatch
End Sub
Private Sub ExcelStopWatch()
Calculations.Range("A1").Value = Format(Time - t + PreviousTimerValue, "hh:mm:ss")
NextTick = Now + TimeValue("00:00:01")
If Calculations.Range("A1").Value > Calculations.Range("B3") Then
With Sheet4.Shapes("TimeBox")
.Fill.ForeColor.RGB = RGB(0, 255, 0)
End With
End If
Application.OnTime NextTick, "ExcelStopWatch"
End Sub
Sub StopClock()
On Error Resume Next
Application.OnTime earliesttime:=NextTick, procedure:="ExcelStopWatch", schedule:=False
With Sheet4.Shapes("TimeBox")
.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End Sub
Sub Reset()
On Error Resume Next
With Sheet4.Shapes("TimeBox")
.Fill.ForeColor.RGB = RGB(192, 192, 192)
End With
Application.OnTime earliesttime:=NextTick, procedure:="ExcelStopWatch", schedule:=False
Calculations.Range("A1").Value = 0
End Sub
I have the code below in a module. Does this happen to anyone else?
Option Explicit
Dim NextTick As Date, t As Date, PreviousTimerValue As Date
Private Sub StartTime()
PreviousTimerValue = Calculations.Range("A1").Value
t = Time
Call ExcelStopWatch
End Sub
Private Sub ExcelStopWatch()
Calculations.Range("A1").Value = Format(Time - t + PreviousTimerValue, "hh:mm:ss")
NextTick = Now + TimeValue("00:00:01")
If Calculations.Range("A1").Value > Calculations.Range("B3") Then
With Sheet4.Shapes("TimeBox")
.Fill.ForeColor.RGB = RGB(0, 255, 0)
End With
End If
Application.OnTime NextTick, "ExcelStopWatch"
End Sub
Sub StopClock()
On Error Resume Next
Application.OnTime earliesttime:=NextTick, procedure:="ExcelStopWatch", schedule:=False
With Sheet4.Shapes("TimeBox")
.Fill.ForeColor.RGB = RGB(255, 0, 0)
End With
End Sub
Sub Reset()
On Error Resume Next
With Sheet4.Shapes("TimeBox")
.Fill.ForeColor.RGB = RGB(192, 192, 192)
End With
Application.OnTime earliesttime:=NextTick, procedure:="ExcelStopWatch", schedule:=False
Calculations.Range("A1").Value = 0
End Sub