Wait Application Method in VBA is used to pauses or stop a running macro until a specified or mentioned time. It returns a Boolean value either true or false. If the specified time arrived, it returns true otherwise it returns False.
VBA Wait Application Method – Syntax
Here syntax for Wait method of application object in VBA.
Application.Wait(Time)
Where
Time: It is a required parameter. It specifies the time at what time you want to resume the macro.
In the above syntax Application represents object and Wait is the method of Application of Application object.
VBA Wait Application Method: Example 1
Please find the below example for Wait method of application object in excel VBA.
Application. The below macro Pauses an application till 4.00 PM today.
Sub Appl_Wait1() Application.Wait "16:00:00" End Sub
VBA Wait Application Method: Example 2
Please find the below example for Wait method of application object in excel VBA.
Application. The below macro Pauses an application for 20 seconds from now.
Sub Appl_Wait2() Application.Wait Now + TimeValue("00:00:20") End Sub
VBA Wait Application Method: Example 3
Please find the below example for Wait method of application object in excel VBA.
‘Display message after 60 seconds.The below macro displays a message like “Your session has expired”
after 60 seconds or 1 hour.
Sub Appl_Wait3() If Application.Wait(Now + TimeValue("0:00:60")) Then MsgBox "Your session has expired" End If End Sub
VBA Wait Application Method – Instructions
Please follow the below steps to execute the VBA code to save the excel file.
Step 1: Open any existing Excel Application.
Step 2: Press Alt+F11 – This will open the VBA Editor.
Step 3: Insert a code module from then insert menu.
Step 4: Copy the above code and paste in the code module which have inserted in the above step.
Step 5: Now press F5 to execute the code.
Step 6: First time run the macro in debug mode (Press F8) to observe the Wait macro result.
Hello, I have a question and would like your comment. Excel has a bug of memory leakage in OLEDB and the solution is to restart Excel. I have successfully written a VBA scrip to kill the EXCEL32 process, then open the workbook and run the macro. Is there anyway to use application.wait or other commands to delay the opening and running the macro after the completion of killing of process.
Wait stops the program execution. Is there any other method by which Wait can run in background and execute something after the time is elapsed while program execution goes uninterrupted?