本文介绍了延迟宏以使事件完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试从宏内部访问外部API函数集时,我发现有必要添加一个延迟,以留出时间让外部API处理选择.

While attempting to access an external API function set from within a macro I found it necessary to add in a delay to allow time for the external API to process a selection.

实施此操作在使用Application.Wait或Application.Sleep时会遇到一些困难.

Implementing this caused a bit of difficulty as using Application.Wait or Application.Sleep wouldn't work.

在线搜索使我尝试使用GetTickCount或timeGetTime-两者都对我不起作用,因为延迟功能无法退出.

Searching online led me to try using GetTickCount or timeGetTime - both of which failed to work for me as the delay function failed to exit.

问题是我该如何实现?

推荐答案

相反,我使用Now和DateAdd函数实现了延迟:

Instead I implemented the delay using the functions Now and DateAdd:

Function Delay(Seconds As Long)
    Dim StopTime As Date: StopTime = DateAdd("s", Seconds, Now)
    Do While Now < StopTime
        DoEvents
    Loop
End Function
Function Delay(Seconds As Single)
    Dim StopTime As Single: StopTime = Timer + Seconds
    Do While Timer < StopTime
        DoEvents
    Loop
End Function

这篇关于延迟宏以使事件完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 05:26