VBA & Macro Problems

Load Text into an Excel VBA UserForm at Runtime

Maira MehtabMaira Mehtab Nov 22, 2026 869 views

Question details

Populate a text box when an Excel VBA UserForm opens and display the form without blocking Excel.

Load Text into an Excel VBA UserForm at Runtime
Product
Microsoft Excel VBA
Device & OS
not provided
Scenario
A workbook needs to display a worksheet value in a UserForm text box at runtime while allowing the user to continue working in Excel.
Observed behavior
The text box contains the worksheet value when the form opens, and the modeless form stays open while the user works in Excel.
Before you start

Use a desktop version of Excel that supports VBA, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Confirm that the workbook contains the worksheet, cell, UserForm, and text box names used in the code, and enable macros only if you trust the file.

Solution 1Recommended

Initialize the text box and show the Excel UserForm modelessly

Use the UserForm's Initialize event to read a cell when the form loads, then open it with vbModeless.

1
Open the VBA editor

In Excel, select Developer > Visual Basic. In the Project Explorer, find your workbook and its UserForm; create one with Insert > UserForm if needed.

2
Check the form and text box names

Select the UserForm and its text box in the VBA editor, and check their (Name) properties in the Properties window. The example uses UserForm1 and TextBox1; change the code if your names differ.

3
Add the initialization code

Double-click the UserForm to open its code window and add: Private Sub UserForm_Initialize() Me.TextBox1.Value = ThisWorkbook.Worksheets("Sheet1").Range("A1").Value End Sub Replace Sheet1 and A1 with the source worksheet and cell. ThisWorkbook refers to the workbook containing the VBA code.

4
Add a macro to show the form

Select Insert > Module and add: Public Sub ShowMyForm() UserForm1.Show vbModeless End Sub

5
Run the macro

Save the workbook, return to Excel, and select Developer > Macros. Choose ShowMyForm and select Run. The form should show the cell value while allowing you to work in Excel.

Initialize the text box and show the Excel UserForm modelessly
Reloading the value: Initialize runs when the form instance is loaded, not every time a hidden form is shown. To run it again, unload the form, for example with Unload UserForm1, before showing it again.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday spreadsheet work. It does not fix Excel's VBA UserForm behavior; check macro and UserForm compatibility before migrating a VBA-dependent workbook.

Open and edit Microsoft Excel XLSX and XLS spreadsheetsUse a familiar spreadsheet interface for everyday workbook tasksWork with worksheet values and formulas in a lightweight office suiteMove common spreadsheet files without rebuilding them from scratch
microsoft office alternative - wps office

Frequently Asked Questions

Where should I put the UserForm_Initialize code?

In the VBA editor, double-click the UserForm in Project Explorer and place the event procedure in that form's code window, not in a standard module.

How do I keep working in Excel while the form is open?

Show the form with UserForm1.Show vbModeless from a macro. Replace UserForm1 with your form's name if it differs.

Why doesn't the text box update when I reopen a hidden form?

Hiding a form keeps its instance loaded, so Initialize does not run again when it is shown. Unload the form before showing it again, or add a separate routine to refresh the text box.

How do I load a value from a different cell?

In UserForm_Initialize, change Worksheets("Sheet1").Range("A1") to the worksheet name and cell you want to use. The example reads from the workbook containing the VBA code.

What file format should I use for the VBA code?

In Excel, select File > Save As and choose Excel Macro-Enabled Workbook (.xlsm) so the workbook can retain its VBA code.