Fix Excel VBA Application.OnTime Not Working with a One-Second Delay
Question details
The user needs to schedule and cancel a VBA macro with Application.OnTime using a one-second delay, but the timer does not work when the time is created from a string.

- Product
- WPS Office Spreadsheet / Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- The user is scheduling a delayed or recurring macro in Excel VBA and wants reliable one-second scheduling and cancellation.
- Observed behavior
- Application.OnTime does not work or cannot be cancelled reliably when the time value is assigned from a string such as "00:00:01".
Enable the Developer tab and confirm that macros or VBA projects are allowed to run. Press Alt+F11 to open the VBA editor and locate the module where the macro is stored.
Store the Scheduled Time in a Public Date Variable
Use this solution when Application.OnTime does not fire or cannot be cancelled because the time is being created from a string.
Application.OnTime expects the EarliestTime argument as a Date value, not a string. Storing the scheduled time in a public Date variable lets you schedule and later cancel the same event reliably.
Press Alt+F11 in WPS Spreadsheet or Excel to open the VBA editor, then locate the module containing your macro.
At the top of a standard module, enter `Public TimerTime As Date` so the scheduled time is visible to scheduling and cancellation code.
In your schedule procedure, set `TimerTime = Now + TimeValue("00:00:01")` instead of using a string directly.
Run `Application.OnTime EarliestTime:=TimerTime, Procedure:="ProcedureName"` using the stored Date value.
To stop the scheduled event, call `Application.OnTime EarliestTime:=TimerTime, Procedure:="ProcedureName", Schedule:=False` with the same stored time.
Cancel a Previously Scheduled OnTime Event
Use this solution if the macro fires or continues after you expect it to stop, or if you need to cancel a pending event before it runs.
Schedule Excel-Compatible Macros Reliably with WPS Spreadsheet
Open the VBA editor in WPS Spreadsheet, store the scheduled time in a public Date variable, and use Application.OnTime with Now + TimeValue to create a cancellable one-second delay.
- 1. Open WPS Spreadsheet: Launch WPS Office Spreadsheet and open the workbook that contains your macro.
- 2. Open the VBA editor: Press Alt+F11 to open the Microsoft Visual Basic for Applications editor in WPS Spreadsheet.
- 3. Insert or open a module: In the Project Explorer, select your workbook and insert or open a standard module where the macro code is stored.
- 4. Enter the Date-variable schedule code: Declare `Public TimerTime As Date`, assign `TimerTime = Now + TimeValue("00:00:01")`, and call `Application.OnTime EarliestTime:=TimerTime, Procedure:="ProcedureName"`.
- 5. Run and cancel the macro: Run the schedule procedure, and use `Application.OnTime EarliestTime:=TimerTime, Procedure:="ProcedureName", Schedule:=False` to cancel the same event when needed.

Frequently Asked Questions
Why does Application.OnTime not work when I use "00:00:01" as a string?
Application.OnTime expects a Date value for EarliestTime. A string like "00:00:01" may not be converted to the correct Date at runtime, so store the time in a Date variable: `TimerTime = Now + TimeValue("00:00:01")`.
How can I cancel a scheduled Application.OnTime event in Excel VBA?
Call Application.OnTime with the exact same EarliestTime and procedure name, and set `Schedule:=False`. Storing the time in a public Date variable makes this reliable.
Does WPS Spreadsheet support Excel VBA macros and Application.OnTime?
WPS Spreadsheet includes a VBA editor and supports Excel-compatible macro workflows. Open it with Alt+F11 and use the same Application.OnTime syntax in a standard module.
Where do I declare the TimerTime variable?
Declare `Public TimerTime As Date` at the top of a standard VBA module so both the scheduling and cancellation code can access the same stored time.
What is the correct macro syntax for a one-second delayed procedure?
Use `TimerTime = Now + TimeValue("00:00:01")` and then `Application.OnTime EarliestTime:=TimerTime, Procedure:="ProcedureName"` to schedule the procedure one second from now.




