Thursday 23 May 2013

How to pause the execution of Macro in Excel

Example :
In below example, you will see how we can pause the execution of macro before executing next statement.
Please note that wscript is not available in Excel VBA Macro. It is available only in vbscript.

Code and Syntax for making the programm wait in Excel VBA is given below.

a = 10
Application.Wait (Now() + TimeValue("0:00:11"))
msgbox a

As you can see in above code, I have used Application.Wait statement.
if you execute this code, you will see that value in a is prompted after 11 seconds.

To wait for say 10 mins, you will have to use below code

a = 10
Application.Wait (Now() + TimeValue("0:10:00"))
msgbox a

So here the format of TimeValue is -

TimeValue("hh:mm:ss"))  - So you can give any value in hour/minute/second to make macro wait for that particular time.

This is how we can pause the execution of macro in Excel.

No comments:

Post a Comment

Popular Posts

Search This Blog