Load Text into an Excel VBA UserForm at Runtime
Question details
Populate a text box when an Excel VBA UserForm opens and display the form without blocking Excel.

- 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.
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.
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.
In Excel, select Developer > Visual Basic. In the Project Explorer, find your workbook and its UserForm; create one with Insert > UserForm if needed.
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.
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.
Select Insert > Module and add: Public Sub ShowMyForm() UserForm1.Show vbModeless End Sub
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.

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.

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.




