How to Make a Word VBA Macro Wait Before Continuing
Question details
The user needs to insert a pause or delay (e.g., five seconds) in a VBA macro between executing commands, without causing syntax or execution errors.

- Product
- Word
- Device & OS
- not provided
- Scenario
- Writing a VBA macro that types a value, waits for a specified number of seconds, and then types a second value.
- Observed behavior
- Using a command like Selection.TypeText directly as the scheduled procedure in Application.OnTime causes a syntax error because the method expects a macro name, not a command.
Ensure you have the Developer tab enabled to access the VBA Editor and save your document as a Macro-Enabled Document (.docm) to prevent losing your script.
Use Application.OnTime with a Separate Macro
The correct way to use Application.OnTime is to pass the name of a second macro rather than writing a VBA command directly into the parameter.
The Application.OnTime method schedules a macro to run at a specific time in the future. Because its second parameter requires a string representing a macro name, passing a direct command like Selection.TypeText will throw an error. You must split your code into two separate macros or use a module-level variable to manage the state.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your word processor.
Create a new Module and write your first macro to type the initial text. Add the Application.OnTime command to schedule a second macro. Example: Application.OnTime When:=Now + TimeValue("00:00:05"), Name:="TypeSecondValue".
Below the first macro, create a new Sub procedure named 'TypeSecondValue'. Inside this macro, write the command to type your second value (e.g., Selection.TypeText Text:="Second").
Place your cursor in the first macro and press F5 to run it. The first value will be typed, and five seconds later, the second macro will automatically trigger and type the second value.

Use the Windows API Sleep Function
Declare the Windows API Sleep function to pause the entire macro execution for a specified number of milliseconds within a single macro.
Automate Tasks Efficiently with WPS Office VBA
WPS Office provides robust support for VBA macros in its advanced editions, allowing you to automate repetitive document tasks, schedule macros, and run customized scripts seamlessly.
- 1. Enable the Developer Tab: Open WPS Writer, go to the settings, and ensure the Developer tab is visible on your ribbon.
- 2. Launch the VBA Editor: Click the 'Macros' button or press Alt + F11 to open the WPS Macro Editor.
- 3. Paste and Run Your Code: Insert a new module, paste your Application.OnTime or Sleep macro, and click Run to automate your document process instantly.

Frequently Asked Questions
Why do I get a syntax error when putting Selection.TypeText in Application.OnTime?
The Application.OnTime method strictly requires the exact string name of an existing macro procedure (e.g., "MyMacro") as its second argument. Providing an executable VBA command directly into the parameter is invalid and causes an error.
What is the difference between Application.OnTime and the Sleep function?
Application.OnTime schedules a macro to execute at a later time, allowing the application to remain active and responsive to user input in the background. The Sleep function completely halts the application thread, meaning the program will be frozen and unresponsive until the specified milliseconds have passed.
Can I cancel a scheduled Application.OnTime macro before it runs?
Yes. You can cancel a scheduled macro by running the Application.OnTime command again with the exact same TimeValue and Macro Name, but adding 'Schedule:=False' at the end of the parameters.




