声明&调用睡眠 API [英] Declaring & Calling The Sleep API

查看:35
本文介绍了声明&调用睡眠 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多关于实现 Sleep API 的主题,但是在知识方面,大多数都比我领先一步,如果有一些指导,将不胜感激.

I have read many threads on implementing the Sleep API however most are a step ahead of where I am at in terms of knowledge to some guidance would be greatly appreciated.

我在 VBA 中有一个宏,我想在步骤之间添加暂停(纯粹是美观而不是功能性),但是我在基本声明和调用方面苦苦挣扎.

I have a macro in VBA which I would like to add pauses to, between steps (purely aesthetic rather than functional) however I am struggling with the basic declaring and calling.

我知道首先我必须声明 api 并且它的代码是...

I understand that first I must declare the api and that the code for this is...

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

然而,我对这应该去哪里感到困惑.它应该放在它自己的模块中还是可以在宏模块的顶部声明?

however, I am confused with regards to where this should go. Should it go in a module of it's own or can it be stated at the top of the macro module?

然后要调用该函数,我只需在...的宏中添加一行即可

Then to call the function do I simply add a line to the macro of...

Call Sleep (1000)

如果有人能帮助解决这个问题,并感谢您对我基本掌握的耐心,我将不胜感激.

I'd appreciate it if anyone can help with this question and appreciate your patience with my basic grasp.

推荐答案

Sleep 的声明应该放在模块的顶部.标准编码模块.

The declaration of Sleep should go to the top of a module. Standard coding module.

你可以省略Call而直接使用

Sleep 1000  ' 1 second delay

现有子文件中的任何位置,所以

anywhere within an existing sub, so

Option Explicit

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

Sub Main()

    ' wait 3 seconds
    Sleep 3000

End Sub

不声明 Sleep sub 的替代方法是

an alternative without declaring the Sleep sub would be

Application.Wait Now + TimeValue("00:00:03") ' waits 3 seconds

这篇关于声明&调用睡眠 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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