如何在Excel中显示运行时钟? [英] How do I show a running clock in Excel?

查看:558
本文介绍了如何在Excel中显示运行时钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Excel 2007的单元格A1中显示一个时钟。我熟悉NOW()和TODAY(),但是它不会像我想要的每1分钟刷新一次。你知道,就像跑步的钟。我只是希望当前时间h:mm在单元格A1。这是可能的吗?



从这个时钟开始,我将进行进一步的计算,就像我上次做X,Y和Z之后有多长时间。谢谢SO。 p>

解决方案

请参阅以下代码(取自这篇文章



将此代码放在VBA中的模块中(开发人员选项卡 - > Visual Basic)

  Dim TimerActive As Boolean 
Sub StartTimer()
Start_Timer
End Sub
Private Sub Start_Timer()
TimerActive = True
Application.OnTime Now()+ TimeValue(00:01:00 ),Timer
End Sub
Private Sub Stop_Timer()
TimerActive = False
End Sub
Private Sub Timer()
如果TimerActive Then
ActiveSheet.Cells(1,1).Value = Time
Application.OnTime Now()+ TimeValue(00:01:00),Timer
End If
End Sub

当工作簿打开时,您可以调用StartTimer功能,并通过添加以下内容每分钟重复一次Visual Basic编辑器中的Visual BasicThis.Workbook类的代码。

  Private Sub Workbook_Open()
Module1.StartTimer
End Sub

现在,每次1分钟通过定时器过程将被调用,并将单元格A1设置为当前时间。


I'd like to show a clock in cell A1 of Excel 2007. I'm familiar with NOW() and TODAY() but it doesn't refresh itself every 1 minute like I want it to. You know, like a running clock. I just want the current time in h:mm to be in cell A1. Is this possible?

From this clock I will do further calculations like How long has it been since I last did Activity X, Y, and Z. Thanks SO.

解决方案

See the below code (taken from this post)

Put this code in a Module in VBA (Developer Tab -> Visual Basic)

Dim TimerActive As Boolean
Sub StartTimer()
    Start_Timer
End Sub
Private Sub Start_Timer()
    TimerActive = True
    Application.OnTime Now() + TimeValue("00:01:00"), "Timer"
End Sub
Private Sub Stop_Timer()
    TimerActive = False
End Sub
Private Sub Timer()
    If TimerActive Then
        ActiveSheet.Cells(1, 1).Value = Time
        Application.OnTime Now() + TimeValue("00:01:00"), "Timer"
    End If
End Sub

You can invoke the "StartTimer" function when the workbook opens and have it repeat every minute by adding the below code to your workbooks Visual Basic "This.Workbook" class in the Visual Basic editor.

Private Sub Workbook_Open()
    Module1.StartTimer
End Sub

Now, every time 1 minute passes the Timer procedure will be invoked, and set cell A1 equal to the current time.

这篇关于如何在Excel中显示运行时钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆