VBA & Macro Problems

Fix Excel Application.OnTime Macro Stops Running in WPS Spreadsheets

Jason MillerJason Miller Nov 13, 2026 869 views

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.

Fix Excel Application.OnTime Macro Stops Running 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In WPS Spreadsheets, press Alt+F11 to open the VBA editor and expand the workbook project in the Project Explorer.

2
Move Workbook_Open to the ThisWorkbook module

Place the Workbook_Open event procedure in the ThisWorkbook module and use it only to start the first run and store the scheduled time.

3
Place the recurring macro in a standard module

Create a standard module and put the CopyValue procedure there so it can be called by Application.OnTime.

4
Replace unqualified cell references

Change Cells and Range calls to fully qualified references, for example ThisWorkbook.Worksheets("Sheet1").Cells(NextRow, 1).Value = Now.

5
Schedule the next run

At the end of CopyValue, call Application.OnTime Now + TimeValue("00:01:00"), "CopyValue" so the next run is always scheduled.

Move Workbook_Open to ThisWorkbook and Fully Qualify Worksheet References
Qualified references prevent scattered writes: Using ThisWorkbook.Worksheets("Sheet1") keeps the recurring value in the intended location even when another workbook is active.

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. 1. Open WPS Spreadsheets and launch the VBA editor: Start WPS Spreadsheets and press Alt+F11 to open the VBA editor.
  2. 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. 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. 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. 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.
Keeps recurring Application.OnTime macros running instead of stopping after a few minutesWrites recorded values to the intended sheet even when the active workbook changesOpens and saves Excel macro-enabled .xlsm files with VBA compatibilityUses the familiar VBA editor interface for a smooth move from Microsoft Excel
microsoft office alternative - wps office

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.