Automatically Refresh a VBA UserForm Text Box in WPS Office
Question details
The user needs to keep a VBA UserForm text box synchronized with a worksheet cell value while the form remains open, without closing and reopening it.

- Product
- WPS Office Spreadsheets
- Device & OS
- not provided
- Scenario
- A WPS Office workbook contains a worksheet cell such as H17 that changes while a VBA UserForm is displayed, and the user wants the txtTotalPrice text box to reflect the latest value automatically.
- Observed behavior
- The text box keeps the original value until the UserForm is closed and reopened; it does not refresh on its own while the form is open.
Open the workbook in WPS Office, enable macros if prompted, and press Alt+F11 to open the VBA editor. Verify that the UserForm text box is named txtTotalPrice and that the source cell is H17 on the sheet named Worksheet, adjusting names to match your workbook.
Use Application.OnTime to Update txtTotalPrice While the Form Is Open
Use this method when you need WPS Office VBA to periodically refresh a UserForm control from a worksheet cell without requiring the user to close and reopen the form.
A standard VBA UserForm does not include a built-in timer control, so the form cannot detect worksheet changes by itself. Application.OnTime lets you schedule a regular macro that copies the current cell value into the text box while the UserForm remains visible.
In WPS Office Spreadsheets, press Alt+F11 to open the VBA editor. In the Project Explorer, find your workbook and the UserForm that contains txtTotalPrice.
In the UserForm code module, paste: Private Sub UserForm_Initialize() txtTotalPrice.Value = Sheets("Worksheet").Range("H17").Value ScheduleRefresh End Sub. Replace Worksheet and H17 with the actual sheet and cell.
In a standard module, paste: Public StopRefresh As Boolean Sub RefreshTotalPrice() UserForm1.txtTotalPrice.Value = Sheets("Worksheet").Range("H17").Value If Not StopRefresh Then ScheduleRefresh End Sub. Use the actual UserForm name shown in the Project Explorer.
In the same standard module, create: Sub ScheduleRefresh() Application.OnTime Now + TimeValue("00:00:01"), "RefreshTotalPrice" End Sub. Change 00:00:01 to the interval you want.
In the UserForm_QueryClose event, add: StopRefresh = True Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), Procedure:="RefreshTotalPrice", Schedule:=False. This stops the scheduled refresh from running after the form closes.

Update a UserForm Text Box Automatically with WPS Office VBA
Open the WPS Office VBA editor, add an Application.OnTime refresh macro, and keep your UserForm text box synchronized with worksheet cell H17 while the form stays open.
- 1. Open your workbook in WPS Office: Launch WPS Office Spreadsheets, open the macro-enabled workbook, and enable macros if the security prompt appears.
- 2. Open the VBA editor: Press Alt+F11 to open the VBA editor, then select your workbook and UserForm in the Project Explorer.
- 3. Add and run the refresh logic: Paste the UserForm_Initialize and Application.OnTime refresh code shown above, adjust the sheet name and cell reference, and run the UserForm to see the text box update.

Frequently Asked Questions
Why doesn't my UserForm text box update automatically when the worksheet cell changes?
A standard VBA UserForm has no built-in timer or data binding, so it only shows the value assigned when the form loaded. You need to schedule a macro, such as with Application.OnTime, to read the cell again while the form is open and update txtTotalPrice.Value.
Can I use Application.OnTime inside a WPS Office VBA UserForm?
Yes. Open the WPS Office VBA editor with Alt+F11, add the scheduling code in a standard module or the UserForm code module, and call Application.OnTime with the time interval and macro name. Make sure macros are enabled when the workbook opens.
How do I stop the automatic refresh when the UserForm closes?
Use the UserForm_QueryClose event and set StopRefresh to True. Also call Application.OnTime with Schedule:=False for the same procedure that was scheduled so the pending refresh does not run after closing.
Do I need to close and reopen the form to refresh the text box value?
No. The Application.OnTime approach refreshes the text box while the form remains visible, as long as the scheduled macro can access the open UserForm and the worksheet cell.




