且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VBA如何在用户窗体中显示实时时钟?

更新时间:2023-02-26 17:12:27

我解决了其他人在所选答案中使用给定代码遇到的问题.我删除了最新时间行,并更改了Label1.caption = Now()改为使用Time().

I solved the issue others were having with the given code in the chosen answer. I removed the latesttime line and i changed Label1.caption = Now() to use Time() instead.

Sub DisplayCurrentTime()
    Dim nextSecond As Date

    nextSecond = DateAdd("s", 1, Now())

    Label1.Caption = Time()

    Application.OnTime _
        Procedure:="DisplayCurrentTime", _
        EarliestTime:=nextSecond
End Sub

然后我在userform_initialize函数中调用了此方法. Label1.caption已更改为我的用户窗体上的相应标签.

I then called this in my userform_initialize function. Label1.caption was changed to the appropriate label on my userform.

感谢所有帮助!