如何获取VBA(Excel)中的DateDiff值(以毫秒为单位)? [英] How to get a DateDiff-Value in milliseconds in VBA (Excel)?

查看:645
本文介绍了如何获取VBA(Excel)中的DateDiff值(以毫秒为单位)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算两个时间戳之间的差异,单位为毫秒。
不幸的是,VBA的DateDiff函数不提供这个精度。
是否有任何解决方法?

I need to calculate the difference between two timestamps in milliseconds. Unfortunately, the DateDiff-function of VBA does not offer this precision. Are there any workarounds?

推荐答案

您可以使用 here 如下: -

You could use the method described here as follows:-

创建一个新的类模块,名为 StopWatch
将以下代码放在 StopWatch 类模块中:

Create a new class module called StopWatch Put the following code in the StopWatch class module:

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 Timer功能,但这只是准确到百分之一一秒钟(厘秒)。

Other methods describe use of the VBA Timer function but this is only accurate to one hundredth of a second (centisecond).

这篇关于如何获取VBA(Excel)中的DateDiff值(以毫秒为单位)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆