Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

ms access - Declaring & Calling The 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.

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

enter image description here


an alternative without declaring the Sleep sub would be

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...