+ Reply to Thread
Results 1 to 6 of 6

vba timer

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    vba timer

    Hello

    i user this code for timer in my excel
    '                                                TIMER CODE START
    Option Explicit
    
    Dim StopTimer           As Boolean
    Dim SchdTime            As Date
    Dim Etime               As Date
    Const OneSec            As Date = 1 / 86400#
    
    Sub ResetBtn_Click()
        StopTimer = True
        Etime = 0
        [Time].Value = "00:00:00"
    End Sub
    Sub StartBtn_Click()
       StopTimer = False
       SchdTime = Now()
     On Error Resume Next
       [Time].Value = Format(Etime, "hh:mm:ss")
       Application.OnTime SchdTime + OneSec, "NextTick"
    End Sub
    
    Sub StopBtn_Click()
        StopTimer = True
        Beep
    End Sub
    
    Sub NextTick()
    
       If StopTimer Then
          'Don't reschedule update
       Else
       On Error Resume Next
          [Time].Value = Format(Etime, "hh:mm:ss")
          SchdTime = SchdTime + OneSec
          Application.OnTime SchdTime, "NextTick"
          Etime = Etime + OneSec
       End If
       
        
    End Sub
    
    '                                                 TIMER CODE END
    and StartBtn_Click in workbook open sub

    if i save and close the file, when i open it the timer start from zero
    how can i keep it continue ?

    thanks

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: vba timer

    Hi e97h,

    You could write a time to a cell in one of your worksheets using an On_Close event. Then when you open your workbook you could read that number to start the timer again from a non zero time.

    If you don't want to use a cell in the workbook, how about using the Tag property in one of your objects and store the closing time there and read it on open?

    Just some ideas...

    Marv
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    Re: vba timer

    first point is better
    but how should i do it? can u help
    i do it but after i open the excel, its stuck in 00:00:00
    Last edited by Undo; 08-18-2019 at 09:47 AM.

  4. #4
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    Re: vba timer

    This the excel file if anyone can help

    thanks
    Attached Files Attached Files

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,447

    Re: vba timer

    Hi e97h,

    See my example attached. See if it does what you need. I tried to make it as simple as possible.

    Total Time Workbook Open Timer.xlsm

  6. #6
    Forum Contributor
    Join Date
    07-14-2019
    Location
    Dubai
    MS-Off Ver
    2019
    Posts
    927

    Re: vba timer

    Thank for help, but its not working
    kindly insert it my sample excel

+ 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. [SOLVED] hwnd timer pause VBA countdown timer
    By jaryszek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-05-2019, 04:25 AM
  2. Countdown timer Working BUT starting the timer repeatedly SPEEDS UP TIMER!
    By Vinospam in forum Excel Programming / VBA / Macros
    Replies: 67
    Last Post: 03-30-2019, 06:42 PM
  3. timer for 30 minutes and timer based events
    By mohak12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2014, 06:20 PM
  4. Replies: 1
    Last Post: 12-12-2012, 08:46 PM
  5. Timer
    By bnwash in forum Excel General
    Replies: 2
    Last Post: 06-14-2007, 02:39 AM
  6. Replies: 1
    Last Post: 03-10-2006, 08:10 AM

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