宏 VBA (excel 2010) - 以用户形式显示系统时间和运行秒数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16278008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Macro VBA (excel 2010) - Display system time with running seconds in user form
提问by user2054091
Please show me on how to display system time with running seconds in userform - vba excel 2010
请告诉我如何在用户表单中以运行秒数显示系统时间 - vba excel 2010
Just like visual basic timer object - but I cant find any like this in macro
就像视觉基本计时器对象一样 - 但我在宏中找不到任何类似的东西
Thanks...
谢谢...
回答by Our Man in Bananas
you can do this as below (found on Ozgrid.Com Forums) :
您可以按如下方式执行此操作(可在Ozgrid.Com 论坛上找到):
in a UserForm with a label called Label1put the below code
在带有名为Label1的标签的用户窗体中放置以下代码
Private Sub UserForm_Initialize()
Me.Label1 = Time
Application.OnTime Time + TimeValue("00:00:01"), "Live_time"
End Sub
Private Sub UserForm_Terminate()
Application.OnTime Time + TimeValue("00:00:01"), "Live_time", , False
End Sub
in a Public module, put this code:
在公共模块中,放置以下代码:
Sub Live_time()
Application.OnTime Time + TimeValue("00:00:01"), "Live_time"
UserForm1.Label1 = Time
UserForm1.Repaint
End Sub
then run the form with the label on it.
然后运行带有标签的表单。
回答by romantique
you could also write this code
Application.OnTime Time + TimeValue("00:00:01"), "Live_time"
UserForm1.Label1 = Time
on the initialize event of the userform.
您也可以
在用户窗体的初始化事件上编写此代码Application.OnTime Time + TimeValue("00:00:01"), "Live_time" UserForm1.Label1 = Time。