Hi all,
I have inserted a stopwatch timer into a userform following the example from the below link. However I am trying to get the time value to save so when I close the document and reopen it the timer continues where it left off. I can save the value by storing it in a cell when I close and save which works fine when I reopen but once I press the start button the value changes back to zero. My code is as follows
Dim dteStart As Date, dteFinish As Date
Dim dteStopped As Date, dteElapsed As Date
Dim boolStopPressed As Boolean, boolResetPressed As Boolean
Private Sub btnReset_Click()
dteStopped = 0
dteStart = 0
dteElapsed = 0
TextBox7 = "00:00:00"
boolResetPressed = True
End Sub
Private Sub btnStart_Click()
Start_timer:
dteStart = Time
boolStopPressed = False
boolResetPressed = False
Timer_Loop:
DoEvents
dteFinish = Time
dteElapsed = dteFinish - dteStart + dteStopped
If Not boolStopPressed = True Then
TextBox7 = dteElapsed
If boolResetPressed = True Then GoTo Start_timer
GoTo Timer_Loop
Else
Exit Sub
End If
End Sub
Private Sub btnStop_Click()
boolStopPressed = True
dteStopped = dteElapsed
End Sub
Private Sub UserForm_Initialize()
TextBox7 = "00:00:00"
TextBox7.Value = Sheet1.Range("A1").Value
End Sub
Private Sub CommandButton4_Click()
Application.DisplayAlerts = False
Sheet1.Range("A1").Value = TextBox7.Value
With ThisWorkbook
.Save
.Close
End With
Application.DisplayAlerts = True
End Sub
Few points about my userform, I have a start,stop and reset button for the timer and another button which saves and closes the worksheet.
Does anyone know of a solution to my problem?
http://www.your-save-time-and-improv...vba-timer.html
Thanks
Bookmarks