VBA Snippets: Sleep

MicrosoftThis post is part of the series on VBA Snippets.

The following VBA snippets can be used to set a pause (sleep) in the code.

The first one needs to be in the declarations at the top of the module:

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

The second is used where you want the code to pause (my recent use was to pause for five seconds after an error and before retrying the action):

Sleep (1000 * 5)

The highlighted section is the time; 1000 milliseconds multiplied by 5 to give me 5 seconds.

What should we write about next?

If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.

Your Name

Your Email

Suggested Topic

Suggestion Details

Leave a Reply

Your email address will not be published. Required fields are marked *