Fix Excel Application.OnTime Macro Stops Running in WPS Spreadsheets
Question details
The user needs to troubleshoot a scheduled VBA macro that records a value every minute but stops after several executions in WPS Spreadsheets.

- Product
- WPS Office Spreadsheets
- Device & OS
- not provided
- Scenario
- A VBA macro uses Application.OnTime to write a value to a worksheet every minute, but the schedule stops before the intended end time.
- Observed behavior
- The macro runs for a few minutes and then stops, or values appear on the active sheet instead of the intended sheet when another workbook or worksheet is active.
Open the VBA editor in WPS Spreadsheets with Alt+F11 and verify that the workbook has the Workbook_Open event and the scheduled macro stored separately. Check that macro security allows macros to run so the OnTime schedule can start.
Move Workbook_Open to ThisWorkbook and Fully Qualify Worksheet References
Use this when the macro stops because the next OnTime call is not scheduled or values are written to the wrong active sheet.
In VBA, unqualified Range and Cells calls target the active sheet. If the user switches workbooks or sheets while the timer is running, the values go to unintended locations, and putting Workbook_Open inside the recurring procedure can prevent the schedule from being re-armed.
In WPS Spreadsheets, press Alt+F11 to open the VBA editor and expand the workbook project in the Project Explorer.
Place the Workbook_Open event procedure in the ThisWorkbook module and use it only to start the first run and store the scheduled time.
Create a standard module and put the CopyValue procedure there so it can be called by Application.OnTime.
Change Cells and Range calls to fully qualified references, for example ThisWorkbook.Worksheets("Sheet1").Cells(NextRow, 1).Value = Now.
At the end of CopyValue, call Application.OnTime Now + TimeValue("00:01:00"), "CopyValue" so the next run is always scheduled.

Store the Scheduled Time and Cancel OnTime When the Workbook Closes
Use this to prevent a hidden scheduled procedure from running after the workbook is closed or to stop the timer at a specific end time.
Fix a Recurring Application.OnTime Macro in WPS Spreadsheets
WPS Spreadsheets supports VBA macros, so you can separate event procedures from the scheduled macro, qualify workbook and worksheet references, and re-arm the timer so the macro keeps running.
- 1. Open WPS Spreadsheets and launch the VBA editor: Start WPS Spreadsheets and press Alt+F11 to open the VBA editor.
- 2. Insert a standard module for the scheduled macro: Insert a standard module and create the CopyValue procedure with fully qualified references such as ThisWorkbook.Worksheets("Sheet1").Cells(NextRow, 1).Value = Now.
- 3. Add the Workbook_Open event: In ThisWorkbook, add Workbook_Open to call CopyValue once and store the first scheduled time in a module-level variable.
- 4. Re-arm Application.OnTime at the end of the macro: Before the procedure ends, schedule the next run with Application.OnTime Now + TimeValue("00:01:00"), "CopyValue" only when the end time has not been reached.
- 5. Save and test the macro-enabled file: Save the workbook as a macro-enabled .xlsm file, close and reopen it, and confirm the macro continues until the scheduled stop time.

Frequently Asked Questions
Why does my Excel Application.OnTime macro stop after a few minutes?
Usually the macro stops because the next OnTime call is missing or because unqualified Cells and Range references write to the active sheet. Put the recurring procedure in a standard module, fully qualify the workbook and worksheet, and schedule the next run at the end of the procedure.
Where should the Workbook_Open code be placed?
Workbook_Open belongs in the ThisWorkbook module. It should only start the first run and store the scheduled time; the scheduled macro itself should live in a standard module.
How do I cancel a scheduled macro when the workbook closes?
Store the scheduled time in a module-level Date variable, then use Workbook_BeforeClose with Application.OnTime EarliestTime:=runTime, Procedure:="CopyValue", Schedule:=False to cancel the pending run.
Can WPS Office open an Excel file that uses Application.OnTime?
Yes. WPS Spreadsheets supports VBA macros and can open macro-enabled Excel workbooks. To make the timer reliable, use explicit ThisWorkbook.Worksheets references and save the file as .xlsm.




