add a timer to my template

G

Guest

I am a cost estimator who works on 2-12 bids a week and I want to add a timer
to my template that simply counts up from zero while the workbook is open
(and cumulatively each time opened) so I can compare my time usage vs. job
profit estimated.

I am a programming rookie, thanks for your assistance.
 
J

JE McGimpsey

One way:

Put this the ThisWorkbook Code module:


Private Sub Workbook_Open()
StartCounting bStart:=True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopCounting
End Sub

Put this in a regular code module:

Public dNextCall As Double

Public Sub StartCounting(Optional bStart As Boolean = False)
Const dINCREMENT As Date = #00:01:00#
If Not bStart Then
With Sheets("Sheet1").Range("A1")
.Value = .Value + dINCREMENT
End With
End If
dNextCall = Now + dINCREMENT
Application.OnTime dNextCall, "StartCounting", Schedule:=True
End Sub

Public Sub StopCounting()
Application.OnTime dNextCall, "StartCounting", Schedule:=False
End Sub

Change the Sheet and range, and the increment, to suit.
 
G

Guest

that works perfectly, thank you.


JE McGimpsey said:
One way:

Put this the ThisWorkbook Code module:


Private Sub Workbook_Open()
StartCounting bStart:=True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopCounting
End Sub

Put this in a regular code module:

Public dNextCall As Double

Public Sub StartCounting(Optional bStart As Boolean = False)
Const dINCREMENT As Date = #00:01:00#
If Not bStart Then
With Sheets("Sheet1").Range("A1")
.Value = .Value + dINCREMENT
End With
End If
dNextCall = Now + dINCREMENT
Application.OnTime dNextCall, "StartCounting", Schedule:=True
End Sub

Public Sub StopCounting()
Application.OnTime dNextCall, "StartCounting", Schedule:=False
End Sub

Change the Sheet and range, and the increment, to suit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top