![](/img/trans.png)
[英]VBA take user input (integer), and input it into a timer Excel 2007
[英]Creaing a VBA timer counter with milliseconds in excel 2007
我有一個這樣的計時器:
Dim SchedRecalc As Date
Sub Recalc()
With Sheet8.Range("A1")
.Value = Format(Time, "hh:mm:ss AM/PM")
End With
Call SetTime
End Sub
Sub SetTime()
SchedRecalc = Now + TimeValue("00:00:01")
Application.OnTime SchedRecalc, "Recalc"
End Sub
Sub Disable()
On Error Resume Next
Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Recalc", Schedule:=False
End Sub
計時器增加一秒,但我也喜歡顯示毫秒
TimeValue()
函數只能計數秒。 如我所見,您正在使用Application.OnTime
函數等待1秒。 您也可以使用Sleep()
從內核庫中獲得它。 嘗試以下操作(僅適用於Windows):
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Sub test()
MsgBox "Wait 10 sek"
Sleep (10000)
MsgBox "Now wait 10 milisek"
Sleep (10)
MsgBox "Ok"
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.