VBA & Macro Problems

Automatically Refresh a VBA UserForm Text Box in WPS Office

Olivia MillerOlivia Miller Nov 13, 2026 869 views

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.

Automatically Refresh a VBA UserForm Text Box in WPS Office
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

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.

2
Add initialization code

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.

3
Create the recurring refresh macro

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.

4
Schedule the next refresh

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.

5
Cancel the timer when closing

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.

Use Application.OnTime to Update txtTotalPrice While the Form Is Open
Timer update is scheduled: When the form is open, the scheduled macro reads cell H17 on the interval you set and assigns the value to txtTotalPrice without reopening the form.
WPS Office VBA solution

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. 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. 2. Open the VBA editor: Press Alt+F11 to open the VBA editor, then select your workbook and UserForm in the Project Explorer.
  3. 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.
Built-in VBA scheduling refreshes UserForm controls without closing the formReads and writes .xlsx, .xlsm, and Excel VBA macro filesFree, lightweight WPS Office interface familiar to Excel usersMacro-enabled spreadsheet workflow with familiar menus
microsoft office alternative - wps office

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.