VBA & Macro Problems

How to Make a Word VBA Macro Wait Before Continuing

Jason MillerJason Miller Oct 23, 2026 869 views

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.

How to Make a Word VBA Macro Wait Before Continuing
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor in your word processor.

2
Write the first macro

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".

3
Create the scheduled macro

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").

4
Run the initial script

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 Application.OnTime with a Separate Macro
Avoid Endless Recursive Loops: Be careful when scheduling macros. If a macro uses Application.OnTime to continuously call itself without an exit condition, it will create an endless loop that is difficult to stop.
Seamless Document Automation

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. 1. Enable the Developer Tab: Open WPS Writer, go to the settings, and ensure the Developer tab is visible on your ribbon.
  2. 2. Launch the VBA Editor: Click the 'Macros' button or press Alt + F11 to open the WPS Macro Editor.
  3. 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.
Fully compatible with Microsoft Word VBA syntax and .docm formatsBuilt-in VBA Editor for seamless coding, debugging, and executionLightweight application ensures scripts run fast without lagging
microsoft office alternative - wps office

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.