To rename a VBA UserForm in Excel for Microsoft 365 on Windows, open the Visual Basic Editor, select the form in Project Explorer, press F4, and change its (Name) property. Then update code that refers to the old form name and compile the project; changing (Name) changes the form’s VBA identifier, not the title users see on screen.
What a UserForm name controls
A UserForm is a form component in a VBA project. Its (Name) property is the identifier other VBA code uses to refer to the form class or its default instance. For example, if a form is named UserForm1, code might open its default instance with UserForm1.Show. Renaming it to frmCustomerEntry means references using the old identifier may need to be changed.
The name is not the same as the form’s visible heading, and it does not rename the controls placed on the form. A textbox named TextBox1 remains TextBox1 unless you change that control’s own (Name) property. Likewise, a button’s name and its displayed label are separate properties. Keeping these distinctions clear makes it easier to identify the correct property and avoid changing more than intended.
How to rename a UserForm in the Visual Basic Editor
These steps apply to desktop Excel on Windows. Save the workbook first, especially if you are changing an established project with many references.
- Open the workbook and press
Alt+F11to open the Visual Basic Editor (VBE). - If Project Explorer is not visible, press
Ctrl+R. Find the workbook’s VBA project and expand its Forms folder if necessary. - Select the UserForm component in Project Explorer. Select the form itself, not a textbox or other control shown on its design surface.
- Press
F4to show the Properties window. If it is not visible, use the VBE View menu to display Properties Window. - Select the first property,
(Name), and type the new identifier, such asfrmCustomerEntry. Press Enter to apply it. - Save the workbook, then use
Debug > Compile VBAProjectin the VBE to check for compile errors.
The new name should be a valid VBA identifier: use letters, digits, and underscores, do not start it with a digit, and do not include spaces or punctuation such as hyphens. A descriptive prefix such as frm is a convention some projects use to make forms easy to recognize; VBA does not require that particular prefix. Choose a name that is distinct from other components and is meaningful to someone maintaining the workbook.
Name versus Caption
The (Name) property identifies the form in VBA. The Caption property supplies the text shown in the form’s title bar when it is displayed. If a user asks to change the words at the top of a form, change Caption, not (Name). For instance, a form can have the internal name frmCustomerEntry while its caption reads Enter customer details.
This separation is useful because the identifier can stay stable and concise for code while the caption can be written for the workbook’s users. A caption may contain spaces and punctuation. A form name may not. Changing the caption generally does not require replacing references to the form in code; changing the name can.
Update code that uses the old name
After a rename, search the VBA project for the old identifier. Look in standard modules, other forms, class modules, and workbook or worksheet event modules. A call such as UserForm1.Show should use the new name if it is intended to open that form. Any declarations that use the form as a type also need review. For example, a variable declared as Dim entryForm As UserForm1 refers to the old class name and should be changed to the new one.
The VBE may update some references in particular editing situations, but do not assume every occurrence has been changed. Use Edit > Find in the VBE to search the current project, or use the project-wide search option if available in your VBE version. Check each result in context: an occurrence in a comment or a string displayed to users may not be a code reference and may not need alteration. Also check any documentation or instructions that name the form.
Code inside the form’s own module that uses Me continues to refer to the current form and normally does not need a change just because the component was renamed. Event procedures for controls are tied to those controls; renaming the form does not rename a button or textbox. Avoid editing generated form code merely to make the rename work.
Opening the renamed form in code
Once the form is called frmCustomerEntry, a simple call to its default instance can use frmCustomerEntry.Show. In larger procedures, creating an explicit instance can make it clearer which form object the code is using. For example:
Public Sub ShowCustomerEntry()
' Create and display an instance of the renamed form.
Dim entryForm As frmCustomerEntry
Set entryForm = New frmCustomerEntry
entryForm.Show
End Sub
This example displays the form modally by default, so the procedure waits while the form is open. A project can also show a form modelessly, which lets the user work in Excel while the form remains open, but the code and lifetime of the form instance should be designed deliberately for that behavior. The form’s name is its class identifier; the variable name entryForm is simply a local name chosen by the procedure.
Before running a macro to test the change, save a copy of the workbook. VBA macros cannot be undone with Ctrl+Z, so a separate copy is a practical way to preserve a recoverable version while checking a project.
Common problems after renaming
- The form title did not change. You changed
(Name), which is for VBA references. SetCaptionto change the visible title. - Compile reports a variable or method is not defined. A remaining reference may still use the old component name, or the new name may have been typed inconsistently. Search for the old name and check spelling and capitalization.
- The new name is rejected. Remove spaces or punctuation, make sure the first character is not a digit, and check that the name does not conflict with another component in the project.
- The form opens from one button but not another. Different event procedures may call it separately. Search the whole project rather than checking only the button you used to test.
- The form name changed but a control reference fails. The form and its controls have separate names. Inspect the control’s own
(Name)property and update code that refers to that control only if you renamed it too.
Compiling is a useful check, but it does not prove that every runtime path behaves correctly. A reference can be assembled dynamically, hidden in an event procedure that has not been exercised, or located in another workbook or add-in. Test the buttons and workflows that open the form, and verify that the form’s inputs and actions still work as expected.
Excel on Mac and Excel for the web
Excel for Mac also includes a VBA editor for desktop workbooks. The editor can typically be opened with Option+F11; on some keyboards you may also need the Fn key, or you can open the Visual Basic Editor from Excel’s Tools > Macro menu. Once in the editor, select the form and change (Name) in its Properties window as described above. Keyboard behavior can vary with the Mac’s keyboard settings.
Excel for the web does not provide the desktop VBA editor for editing or running VBA macros. Open the workbook in desktop Excel to rename a UserForm. A workbook containing VBA must be saved in a macro-enabled format such as .xlsm if its VBA project is to be retained; saving in a format that does not support VBA can remove the macros.
Frequently Asked Questions
Can I rename a UserForm while the workbook is running?
Usually, the practical way to rename a form is to edit its component’s (Name) property in the VBE while working on the project, not to change the form name from a running macro. Close the form and make the change in the editor, then update references and compile.
Does renaming a UserForm change its caption?
No. (Name) is the VBA identifier; Caption is the text displayed in the title bar. Change the property that matches the result you want.
Will VBA automatically update every reference?
Do not rely on that. Review project code for the old name and compile after updating references. References in comments, text, or external workbooks may require separate attention.
Can the form name contain spaces?
No. Use a valid identifier such as frmOrderLookup, without spaces or hyphens. Use the Caption property for user-facing text that needs spaces.
Can I rename a UserForm in Excel for the web?
No. Excel for the web does not include the VBE needed to edit VBA UserForms. Use desktop Excel on Windows or Mac to make the change.
Related
- Append Queries in Power Query: How to Combine Tables
- Power Query Editor: What It Is, How It Works, and Why
- Excel Data Validation Icon: What It Looks Like and Does
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- How to Delete Blank Rows in Excel with a VBA MacroTo delete blank rows in Excel with a macro, select the data range, run a VBA procedure that…
- VBA MsgBox Yes/No: How to Get and Handle the AnswerTo show Yes and No buttons in VBA and read the user’s choice, use vbYesNo and assign the…
- Columns in Excel VBA: Select, Count, and Use ThemIn Excel VBA, use a worksheet’s Columns property to refer to one or more entire worksheet columns, such…
- VBA Find the Last Row With Data in an Excel WorksheetTo find the last row in a known column, start at the bottom of that column and use…
- Excel VBA Find LookIn: What It Means and How to Use ItIn Excel VBA, LookIn is an argument of the Range.Find method that tells Excel what kind of content…
- Excel UserForm TextBox: How to Wrap TextTo wrap text in an Excel UserForm TextBox, set its MultiLine property to True and its WordWrap property…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.