宣告&调用睡眠API [英] Declaring & Calling The Sleep API

查看:125
本文介绍了宣告&调用睡眠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,而只需使用

You can omit Call and just use

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子项的替代方法是

an alternative without declaring the Sleep sub would be

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

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

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