To rename a UserForm in Excel VBA, open the Visual Basic Editor, select the form in Project Explorer, press F4, and change its (Name) property. This changes the form’s code name, not the title shown on the form. Before you finish, check code that refers to the old name and compile the project.
What You’ll Need
- Desktop Excel for Windows or Mac. Excel for the web cannot edit or run VBA projects.
- A workbook with a VBA project that you can edit. If the project is locked for viewing, you will need permission or the password to unlock it.
- A saved backup of the workbook. Renaming through the Properties window is a design-time edit, but changes to code and macros are not reversible with Ctrl+Z.
If the workbook contains macros, keep it in a macro-enabled format such as .xlsm or .xlsb. Saving it as .xlsx removes VBA content.
Step-by-Step
- Save a working copy. In Excel, use File > Save As and save a duplicate before editing. Keep the original unchanged until you have confirmed that the renamed form opens and behaves as expected. This is especially important in a shared workbook or one with many macros, where the form name may be referenced in several modules.
- Open the Visual Basic Editor. In Excel for Windows, press Alt+F11, or choose Developer > Visual Basic. If the Developer tab is not visible, enable it through File > Options > Customize Ribbon and select Developer. On Mac, open the editor from Developer > Visual Basic when available, or use Tools > Macro > Visual Basic Editor in builds that show that menu. The Mac shortcut may require Option+F11 or Fn+Option+F11, depending on the keyboard. The VBE menus may look slightly different by platform.
- Find the form in Project Explorer. If the pane is hidden, press Ctrl+R on Windows or choose View > Project Explorer. Expand the project for the workbook you intend to edit. Under the project, find the Forms folder and locate the target form, often named something like
UserForm1. Confirm the workbook or project name before changing anything; multiple open workbooks can appear in this pane. - Select the form object, not a control on it. Click the form’s entry in Project Explorer. If the form is open in its designer, click a blank area of the form rather than a button, text box, or label. This distinction matters because the Properties window shows properties for whichever object is currently selected. The form’s name appears in the Properties window; a control’s name appears instead if you selected a control.
- Show the Properties window and edit (Name). Press F4, or choose View > Properties Window. At the top of the property list, find
(Name). Click its value, replace the old name with the new one, and press Enter. For example, changeUserForm1toUserFormCustomerEntry. Do not type parentheses around the property name; they identify the property in the list, not part of the value. - Use a valid, descriptive VBA name. Start with a letter, and use letters, numbers, or underscores. Do not include spaces, hyphens, or punctuation. A name such as
frmCustomerEntryorUserFormCustomerEntryis valid and communicates the form’s purpose. Avoid using a VBA reserved word, such asNext, as the name. Press Enter to commit the change; clicking elsewhere before confirming may leave the edit incomplete. - Check the form’s Caption separately. The
Captionproperty controls the text displayed in the form’s title bar. It does not control the name used in VBA code. For example, you can set(Name)tofrmCustomerEntrywhile settingCaptiontoEnter Customer Details. Change Caption only if you also want to alter the wording users see when the form opens. - Review code that uses the old name. Search the project for the previous name, including code in standard modules, worksheets, ThisWorkbook, and the form’s own code module. Update references that identify the form itself, but do not replace every matching word automatically: a comment, label, or unrelated variable might contain the same text. Pay particular attention to code that opens the form and any text-based calls that refer to a form by name.
- Test a form reference and compile. A typical reference after the rename might look like this, assuming the form’s new
(Name)isUserFormCustomerEntry:
Private Sub OpenCustomerForm()
Dim frm As UserFormCustomerEntry
Set frm = New UserFormCustomerEntry
frm.Show ' Display the renamed form.
End Sub
This example belongs in a standard module and assumes that the form is named exactly as shown. If your existing code uses the default form instance, update that reference to the new form name instead. In the VBE, choose Debug > Compile VBAProject (the project name may replace VBAProject) to catch unresolved names and other compile errors. Then run the normal command or button that opens the form and verify its controls and event code. Save the workbook after the checks pass. Save a copy before running any macro: VBA changes cannot be undone with Ctrl+Z.
Common Mistakes
- Changing Caption instead of (Name). The form’s visible heading may change, but code that calls the old form name will still refer to the old identifier. Set
(Name)to rename the form for VBA; use Caption only for its displayed title. - Renaming a control by mistake. If a button or text box is selected, its Properties window is active. Check the selected item in Project Explorer or click a blank part of the form designer before changing the property.
- Using spaces or punctuation. A name such as
Customer Entryis not a suitable VBA identifier. Use a compact name such asfrmCustomerEntry. - Assuming all references update. Do not assume that every code reference or string containing the old name has changed. Search the project and test the form after the rename.
- Saving in a format that drops VBA. An
.xlsxfile cannot retain VBA macros. Keep the edited workbook in a VBA-capable format.
Tips
Choose a naming convention and use it consistently. For example, prefix forms with frm, buttons with cmd, and text boxes with txt, followed by a short description. This makes it easier to distinguish the UserForm itself from the controls placed on it. The prefix is a convention, not a requirement imposed by Excel.
Rename forms while the project is still small, before many procedures depend on their names. If you are taking over an existing workbook, first search the project and note how forms are opened. This gives you a short checklist for the test after the rename. Keep user-facing wording in Caption and internal identifiers in (Name); the two can be different without causing a problem.
Use the VBE’s Find command to inspect matches in the current project. Read each result in context before editing it. A direct form call and a comment may contain the same old name but need different treatment. If you have code that constructs a form name as text, check that string too. Compile after making the edits, then test the actual workflow rather than relying only on the absence of compile errors.
On Mac, the form properties and VBA naming rules work similarly, but keyboard shortcuts and some menu locations can vary by Excel build and keyboard settings. Use the VBE menus if a function-key shortcut does not work. Excel for the web does not provide the VBA editor, so open the workbook in desktop Excel to perform this task.
Troubleshooting
The Properties window does not show (Name). Check that you selected the UserForm itself rather than one of its controls. Click the form’s item in Project Explorer or click a blank area of its designer, then reopen Properties with F4. If the window is missing, use View > Properties Window.
The new name is rejected. Remove spaces, hyphens, and other punctuation, make sure the first character is a letter, and check that the value is not a reserved VBA word. Try a descriptive identifier such as frmOrderLookup. Press Enter after typing the value so the VBE commits it.
The form no longer opens or code shows a compile error. Search the entire VBA project for the old form name and inspect each match. Update code references to the form’s new name, including any dynamically constructed references stored as text. Then choose Debug > Compile VBAProject and resolve the first reported error; later errors may be consequences of the first one. Run the opening procedure again after the project compiles.
The title bar still shows the old wording. That is controlled by the form’s Caption property. Set Caption to the wording you want users to see; changing it does not rename the VBA identifier.
You cannot edit the project. Confirm that the correct workbook is open and that its VBA project is not locked. A read-only workbook may also prevent saving changes. If you do not have permission to unlock or edit the project, ask its owner rather than trying to bypass the protection.
Frequently Asked Questions
Does renaming a UserForm change the text users see?
Not by itself. The (Name) property is the identifier used by VBA. Change Caption separately to change the form’s visible title.
Can I rename a UserForm while the workbook is open?
Yes, in desktop Excel, provided the VBA project is editable. Open the VBE, change the property, update references, and test before saving.
Will renaming the form rename its buttons and text boxes?
No. The form and each control have their own (Name) property. Renaming the form does not rename its controls or their event procedures.
Can I use spaces in a UserForm name?
No. Use a VBA-compatible identifier without spaces, such as frmProductSearch. A space-containing phrase can be used as the form’s Caption instead.
Can I do this in Excel for the web?
No. Excel for the web does not include the VBA editor. Open the workbook in desktop Excel for Windows or Mac to rename the UserForm.
Can I undo the rename with Ctrl+Z?
Do not rely on it. VBE edits are not reliably undone through Excel’s worksheet undo history. Save a backup first, and if needed, restore the old name manually and correct the affected references.
Related
- Excel Won’t Insert a Row? Causes, Fixes, and Workarounds
- Excel Print Area Greyed Out: Why It Happens and Fixes
- Excel Protect Sheet Greyed Out? Causes and Fixes
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Dictionary Early Binding: Setup, Benefits, and LimitsYes. To use a VBA Dictionary with early binding in Excel for Microsoft 365 on Windows, add a…
- VBA Open an Excel File and Copy Data into a WorkbookTo open an Excel file and copy its data with VBA, use Workbooks.Open to open the source workbook,…
- Excel VBA Button: Add, Assign, and Fix Macro ButtonsAn Excel VBA button is a clickable control that runs a macro in a workbook. In Excel for…
- VBA Function Return String: Syntax and ExamplesYes. A VBA function returns a string when its declaration ends in As String; inside the function, assign…
- VBA MsgBox Default Button: Set It and Choose SafelyIn VBA, a MsgBox uses its first button as the default unless you specify otherwise. To make another…
- Excel VBA Date String Formatting ExplainedIn Excel VBA, use Format$ to turn a date value into a formatted text string, such as Format$(Date,…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.