vba - 如何在 VBA (Excel) 中获取以毫秒为单位的 DateDiff-Value?

标签 vba excel datediff

我需要计算两个时间戳之间的差异(以毫秒为单位)。 不幸的是,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/

相关文章:

vba - 在 VBA 中,创建对象与不创建对象时的语法是否不同?

excel - 如何将分类值转换为 Excel 中的列?

sql-server-2012 - DateDiff - 夏令时问题

vba - RibbonXml togglebutton OnAction 找不到回调函数

excel - VBA 使用不等式替换

vba - 使用vba创建 "color scale"(避免条件格式)

excel - 如何使用另一个单元格的值参数化函数的范围参数

c# - com 异常 HRESULT : 0x800A03EC

表中所选记录的一列上的 MySQL 时间差

date - 使用 Groovy 计算两个日期之间的月差