Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause for specific amount of time? (Excel/VBA)

Tags:

excel

vba

I have an Excel worksheet that has the following macro. I'd like to loop it every second but danged if I can find the function to do that. Isn't it possible?

Sub Macro1() ' ' Macro1 Macro ' Do     Calculate     'Here I want to wait for one second  Loop End Sub 
like image 878
Keng Avatar asked Oct 09 '09 15:10

Keng


People also ask

How do you pause a macro for 5 seconds?

You can also use the following: Application. Wait (Now + TimeValue("00:00:05")). This forces your macro to wait 5 seconds, before it continues with the next line of code.

How do you wait time in VBA?

Wait method only accepts one argument: time. To wait 5 seconds, like I did in the demo above, you feed Application. Wait the current time with the Now function. Then, you use the TimeValue function to add 5 seconds to the current time.

How do you put wait in Excel macro?

First, use the keyword “Application” and type a dot (.) to get the list of properties and methods. After that, select or type the “Wait” method. Now, specify the “Time” argument to tell VBA that how much time you want to wait. In the end, run the code to put wait for all the activities in Excel.

Is there a sleep function in VBA?

VBA Sleep function is a windows function present under windows DLL files which is used to stop or pause the macro procedure from running for a specified amount of time after that certain amount of we can resume the program.


1 Answers

Use the Wait method:

Application.Wait Now + #0:00:01# 

or (for Excel 2010 and later):

Application.Wait Now + #12:00:01 AM# 
like image 133
Ben S Avatar answered Oct 09 '22 07:10

Ben S