Active Clock

richblake74

Active Member
Joined
Dec 30, 2006
Messages
284
Office Version
  1. 365
Platform
  1. MacOS
Is there anyway of getting an "Active Clock" in a cell.
I know the =now() thing, but this is not what I am looking for,
I would like to get a clock that updates by the minute, without having to select a cell, or make excel do a calculation.
Hope you are all having fun with excel 2007
richblake74 :rolleyes:
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
richblake74,

<font face=Courier New>Put the following code in a code module. (Time format - 13:30)

<SPAN style="color:#00007F">Sub</SPAN> StartTime()
<SPAN style="color:#00007F">Dim</SPAN> TargetHour
    <SPAN style="color:#00007F">If</SPAN> Minute(Now) = 59 <SPAN style="color:#00007F">Then</SPAN>
        TargetHour = Hour(Now) + 1
    <SPAN style="color:#00007F">Else</SPAN>
        TargetHour = Hour(Now)
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    RunWhen = TimeSerial(TargetHour, Minute(Now) + 1, 0)
    RunWhat = "UpdateClock"
    Application.OnTime earliesttime:=RunWhen, Procedure:=RunWhat, schedule:=<SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> UpdateClock()
    Sheets("Sheet1").Range("A1").Value = "=Now()"
    StartTime
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

Put this code in "ThisWorkbook"

You will have to run the "StartTime" macro to get things going by putting it in <SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open() at startup.
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Open()
    StartTime
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

<SPAN style="color:#00007F">To</SPAN> stop the timer when you close the book
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_Close()
    Application.OnTime earliesttime:=RunWhen, Procedure:=cRunWhat, schedule:=<SPAN style="color:#00007F">False</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>


Hope this helps.
Gary
</FONT>
 
Upvote 0
Thank you

Does not seem to work but thanks for your help,,,
I am using the Mac version, maybe this is the problem..
 
Upvote 0
richblake74,

Well...lets make sure everything is in place.

Is your sheet named "Sheet1". If not change that in the code to be your sheet name.

The first code goes into code "module"
The second in the "ThisWorkbook"

To start the process, it is easiest to close and reopen the workbook.
You can also click anywhere in the StartTimer code and click the run (right) arrow above.

See if that helps.

Gary
 
Upvote 0
Gary

Thanks for all your efforst Gary..
Sub UpdateClock() this keeps getting highlighted, in yellow
I am not good at all with this VB stuff.
Tried many times.
I appreciate all the effort you have made.
I think I will just look at my Wrist Watch
Sincerely
 
Upvote 0
This is a bit simpler:

Code:
Dim NextTick As Date

Sub TickTock()
Range("A1").Value = Now()
NextTick = Now + TimeValue("00:00:01")
Application.OnTime NextTick, "TickTock"
End Sub

Sub StopClock()
Application.OnTime earliesttime:=NextTick, procedure:="TickTock", schedule:=False
End Sub

ALT + F11 to open the Visual Basic Editor. Insert > Module. Copy the above code and paste it in. Then close the VBE.

ALT + F8, click on TickTock and click the Run button to start the clock. The time should be displayed in A1 - you can adjust the time format in A1 to suit.

To stop the clock ALT+F8, click StopClock and click Run.
 
Upvote 0
active Clock

that worked great, now final question...
do i have to Stop the clock to close the Excel program, i am guessing I do as each time I try and close the workbook, without stopping the clock, it keeps reopening.
Is there any way I can close the work book without having to stop the clock??????
One more thing also, If the clock is running and I try to go to another sheet in the book, I get a runtine error...
 
Upvote 0
Re: active Clock

Is there any way I can close the work book without having to stop the clock??????

Yes :)

Right click the Excel logo just to the left of File on the menu and select View Code. Paste in the following

Code:
Private Sub Workbook_BeforeClose(cancel As Boolean)
Call StopClock
End Sub

then close the code window. When you close the workbook the timer will stop.
 
Upvote 0
Thank you sir,,,
now when I open it the clock should be running without me doing anything....
have a great week and thank you for all your help
 
Upvote 0
Ah - to have the clock start automatically you need to add this to the code that you just placed in the workbook code module:

Code:
Private Sub Workbook_Open()
Call TickTock
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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