Timer In Status Bar

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
Is there anyway that a timer can be put in a workbook and counts up every time its opened? When I start a new project I want to see how long it takes, so from the moment I start it I want it to count up and then stop when I close it. Then when I open it again the next day I want it to continue from where it left of and so on. Possible? Thanks.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Use a Defined Name to hold your Total Time.
Add each sessions total time to the name upon close.
 
Upvote 0
I think this is working up to 24 hours.
However it will not keep track after 24 hrs Total Time.
Using format "[h]:mm" doesn't work.
Can anyone fix it to track beyond 24 hrs?

Rich (BB code):
Private Sub Workbook_Open()
    ProjectTimeSetup
    ThisWorkbook.Names("StartTime").RefersTo = Now
    UpdateProjTime
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    UpdateProjTime
    ThisWorkbook.Names("TotalTime").RefersTo = TotalTime + SessionTime
End Sub
Rich (BB code):
Dim StartTime
Dim EndTime
Public SessionTime
Public TotalTime
Const updateSecs = 60 'interval of seconds to update status bar

Sub UpdateProjTime()
    StartTime = Evaluate("StartTime")
    TotalTime = Evaluate("TotalTime")
    EndTime = Now
    SessionTime = EndTime - StartTime
    Application.StatusBar = "Session Time: " & Format(SessionTime, "h:mm") _
             & " | Total Time: " & Format(TotalTime + SessionTime, "h:mm")
    TimerStart
End Sub

Sub ProjectTimeSetup()
    Dim arr As Variant, n As Variant
    arr = Array("StartTime", "TotalTime")
    For Each n In arr
    If IsError(Evaluate(n)) Then _
        ThisWorkbook.Names.Add Name:=n, RefersTo:=0
    Next n
End Sub

Sub TimerStart()
    Application.OnTime _
        EarliestTime:=Now + TimeSerial(0, 0, updateSecs), _
        Procedure:="UpdateProjTime"
End Sub
 
Upvote 0
I think this is working up to 24 hours.
However it will not keep track after 24 hrs Total Time.
Using format "[h]:mm" doesn't work.
Can anyone fix it to track beyond 24 hrs?

Rich (BB code):
Private Sub Workbook_Open()
    ProjectTimeSetup
    ThisWorkbook.Names("StartTime").RefersTo = Now
    UpdateProjTime
End Sub
 
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    UpdateProjTime
    ThisWorkbook.Names("TotalTime").RefersTo = TotalTime + SessionTime
End Sub
Rich (BB code):
Dim StartTime
Dim EndTime
Public SessionTime
Public TotalTime
Const updateSecs = 60 'interval of seconds to update status bar
 
Sub UpdateProjTime()
    StartTime = Evaluate("StartTime")
    TotalTime = Evaluate("TotalTime")
    EndTime = Now
    SessionTime = EndTime - StartTime
    Application.StatusBar = "Session Time: " & Format(SessionTime, "h:mm") _
             & " | Total Time: " & Format(TotalTime + SessionTime, "h:mm")
    TimerStart
End Sub
 
Sub ProjectTimeSetup()
    Dim arr As Variant, n As Variant
    arr = Array("StartTime", "TotalTime")
    For Each n In arr
    If IsError(Evaluate(n)) Then _
        ThisWorkbook.Names.Add Name:=n, RefersTo:=0
    Next n
End Sub
 
Sub TimerStart()
    Application.OnTime _
        EarliestTime:=Now + TimeSerial(0, 0, updateSecs), _
        Procedure:="UpdateProjTime"
End Sub

^
 
Upvote 0
24+ fixed...doh!
Code:
Option Explicit
Dim StartTime
Dim EndTime
Public SessionTime
Public TotalTime
Const updateSecs = 60 'interval of seconds to update status bar

Sub UpdateProjTime()
    StartTime = Evaluate("StartTime")
    TotalTime = Evaluate("TotalTime")
    EndTime = Now
    SessionTime = EndTime - StartTime
    Application.StatusBar = "Session Time: " & Application.WorksheetFunction.Text(SessionTime, "[h]:mm") _
             & " | Total Time: " & Application.WorksheetFunction.Text(TotalTime + SessionTime, "[h]:mm")
    TimerStart
End Sub

Sub ProjectTimeSetup()
    Dim arr As Variant, n As Variant
    arr = Array("StartTime", "TotalTime")
    For Each n In arr
    If IsError(Evaluate(n)) Then _
        ThisWorkbook.Names.Add Name:=n, RefersTo:=0
    Next n
End Sub

Sub TimerStart()
    Application.OnTime _
        EarliestTime:=Now + TimeSerial(0, 0, updateSecs), _
        Procedure:="UpdateProjTime"
End Sub
Code:
Private Sub Workbook_Open()
    ProjectTimeSetup
    ThisWorkbook.Names("StartTime").RefersTo = Now
    UpdateProjTime
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    UpdateProjTime
    ThisWorkbook.Names("TotalTime").RefersTo = TotalTime + SessionTime
End Sub
 
Upvote 0
There seems to be 3 codes here. Do I have to run them all manually or does it do it all automatically?
 
Upvote 0
You will need this code in any WB you track.
It runs on it's own each time you open the book
Go to : http://www.contextures.com/xlvba01.html
for help on installing


This goes in a Regular Module
Code:
Option Explicit
Dim StartTime
Dim EndTime
Public SessionTime
Public TotalTime
Const updateSecs = 60 'interval of seconds to update status bar

Sub UpdateProjTime()
    StartTime = Evaluate("StartTime")
    TotalTime = Evaluate("TotalTime")
    EndTime = Now
    SessionTime = EndTime - StartTime
    Application.StatusBar = "Session Time: " & Application.WorksheetFunction.Text(SessionTime, "[h]:mm") _
             & " | Total Time: " & Application.WorksheetFunction.Text(TotalTime + SessionTime, "[h]:mm")
    TimerStart
End Sub

Sub ProjectTimeSetup()
    Dim arr As Variant, n As Variant
    arr = Array("StartTime", "TotalTime")
    For Each n In arr
    If IsError(Evaluate(n)) Then _
        ThisWorkbook.Names.Add Name:=n, RefersTo:=0
    Next n
End Sub

Sub TimerStart()
    Application.OnTime _
        EarliestTime:=Now + TimeSerial(0, 0, updateSecs), _
        Procedure:="UpdateProjTime"
End Sub


This goes in the Workbook Module
Code:
Private Sub Workbook_Open()
    ProjectTimeSetup
    ThisWorkbook.Names("StartTime").RefersTo = Now
    UpdateProjTime
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    UpdateProjTime
    ThisWorkbook.Names("TotalTime").RefersTo = TotalTime + SessionTime
End Sub
 
Upvote 0
Done as you said but it come up with an error and when I selected debug I think it pointed to

Code:
SessionTime = EndTime - StartTime
 
Upvote 0
This must be a hard request, as loads have viewed the thread but little replies!
 
Upvote 0

Forum statistics

Threads
1,224,538
Messages
6,179,412
Members
452,912
Latest member
alicemil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top