+ Reply to Thread
Results 1 to 6 of 6

Userform Stopwatch Timer. Saving time value.

Hybrid View

Mastaglio Userform Stopwatch Timer.... 12-12-2016, 09:15 AM
davesexcel Re: Userform Stopwatch Timer.... 12-12-2016, 09:21 AM
Mastaglio Re: Userform Stopwatch Timer.... 12-12-2016, 09:27 AM
Mastaglio Re: Userform Stopwatch Timer.... 12-12-2016, 09:32 AM
Mastaglio Re: Userform Stopwatch Timer.... 12-12-2016, 09:33 AM
kasan Re: Userform Stopwatch Timer.... 12-12-2016, 09:33 AM
  1. #1
    Registered User
    Join Date
    10-18-2016
    Location
    Newcastle, England
    MS-Off Ver
    2016
    Posts
    6

    Userform Stopwatch Timer. Saving time value.

    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

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Userform Stopwatch Timer. Saving time value.

    I'm thinking it would be here
    'TextBox7 = dteElapsed'

    possibly something in the range of:
     TextBox7 =textbox7 +  dteElapsed
    Something like that anyway.....

  3. #3
    Registered User
    Join Date
    10-18-2016
    Location
    Newcastle, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Userform Stopwatch Timer. Saving time value.

    Hi Dave, thanks for the quick reply. I get a run-time error 13 when I try this?

  4. #4
    Registered User
    Join Date
    10-18-2016
    Location
    Newcastle, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Userform Stopwatch Timer. Saving time value.

    Actually ignore that, I managed to solve it using:

     TextBox7 = Sheet1.Range("A1").Value + dteElapsed
    Wow this forum is good, thanks Dave.

  5. #5
    Registered User
    Join Date
    10-18-2016
    Location
    Newcastle, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Userform Stopwatch Timer. Saving time value.

    double post
    Last edited by Mastaglio; 12-12-2016 at 09:34 AM. Reason: double post

  6. #6
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Userform Stopwatch Timer. Saving time value.

    Because Dim dteElapsed is Date and Textbox7.Text is String

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Stopwatch / Timer
    By bmasella in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 07-27-2015, 07:19 PM
  2. Formatting Time Label in Excel UserForm StopWatch
    By Mr.Biscuit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2014, 12:14 PM
  3. Creating a Conditional StopWatch/Timer
    By Aloa123 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2012, 09:36 AM
  4. Stopwatch/Timer
    By nbarron in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2011, 04:18 AM
  5. Stopwatch/timer
    By Huwbob in forum Excel General
    Replies: 8
    Last Post: 10-18-2011, 08:46 PM
  6. Stopwatch or using timer of other program
    By banded08 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2009, 03:10 AM
  7. Stopwatch/Timer
    By Baron808 in forum Excel General
    Replies: 1
    Last Post: 09-02-2008, 10:27 AM
  8. [SOLVED] template timer stopwatch
    By wamay in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-15-2006, 05:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1