我需要计算两个时间戳之间的差异(以毫秒为单位)。 不幸的是,VBA 的 DateDiff 函数不提供这种精度。 有什么解决办法吗?
最佳答案
您可以使用here描述的方法如下:-
创建一个名为StopWatch
的新类模块
将以下代码放入 StopWatch
类模块中:
Private mlngStart As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub StartTimer()
mlngStart = GetTickCount
End Sub
Public Function EndTimer() As Long
EndTimer = (GetTickCount - mlngStart)
End Function
您使用的代码如下:
Dim sw as StopWatch
Set sw = New StopWatch
sw.StartTimer
' Do whatever you want to time here
Debug.Print "That took: " & sw.EndTimer & "milliseconds"
其他方法描述了 VBA 计时器函数的使用,但这仅精确到百分之一秒(厘秒)。
关于vba - 如何在 VBA (Excel) 中获取以毫秒为单位的 DateDiff-Value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/939230/