Excel教程:在Excel中制作一个简易的电子时钟
发布时间: 2022-03-11 来源: 网络 编辑: word12345.com 阅读: 1 关键词: Excel教程

本文为《别怕,Excel VBA其实特别简单(第3版)》随书问题参考答案

在ThisWorkbook模块中写入下面的过程:

Private Sub Workbook_Open()
Call OnTime方法
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime StartTime, "更新时间", , False
End Sub

新插入一个模块,在其中写入下面的代码:

Public StartTime As Date

Sub OnTime方法()
StartTime = Now() + TimeValue("00:00:01")
Application.OnTime StartTime, "更新时间"
End Sub

Sub 更新时间()
Range("B3") = Format(Now(), "yyyy-mm-dd hh:mm:ss")
Call OnTime方法
End Sub

保存、关闭,并重新打开工作簿,就能在活动工作表的B3单元格看到简易的电子时钟了。

热门教程

点击排行

最新教程