如何在excel vba中给出不到一秒的时间延迟? [英] How to give a time delay of less than one second in excel vba?

查看:2166
本文介绍了如何在excel vba中给出不到一秒的时间延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在一段时间后不到1秒重复一个事件。我尝试使用以下代码

i want to repeat an event after a certain duration that is less than 1 second. I tried using the following code

Application.wait Now + TimeValue ("00:00:01")

但这里最短的延迟时间是1秒。如何给予一半的延迟?

But here the minimum delay time is one second. How to give a delay of say half a seond?

推荐答案

您可以使用API​​调用和睡眠:

You can use an API call and Sleep:

将其放在模块的顶部:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

然后你可以按照这样的过程调用它:

Then you can call it in a procedure like this:

Sub test()
Dim i As Long

For i = 1 To 10
    Debug.Print Now()
    Sleep 500    'wait 0.5 seconds
Next i
End Sub

这篇关于如何在excel vba中给出不到一秒的时间延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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