To rename a VBA module in Excel, open the Visual Basic Editor, select the module in the Project Explorer, change its Name property in the Properties window, and press Enter. If the Properties window is not visible, press F4 to show it. You cannot rename a module by right-clicking it and choosing Rename — that option does not exist for modules — and you cannot change the name of a document module (the ones named Sheet1, ThisWorkbook, etc.) at all. This guide covers both cases and the errors you may hit along the way.

What You'll Need

  • Excel with macros enabled (the Developer tab visible, or access to the Visual Basic Editor via Alt+F11).
  • A workbook that contains at least one standard module or class module. If you only have sheet and workbook modules, there is nothing to rename.
  • The workbook should be saved as a macro-enabled file (.xlsm or .xlsb) if you want the new name to persist.

Step-by-Step

  1. Open the Visual Basic Editor. In Excel, press Alt+F11, or go to Developer > Visual Basic. The VBE opens in its own window.
  2. Show the Project Explorer. If the left-hand tree of your workbook is not visible, press Ctrl+R or choose View > Project Explorer. Labels can differ slightly by Excel version and region, but the shortcut is consistent.
  3. Expand your workbook node. Click the + next to VBAProject (YourWorkbook.xlsm), then expand the Modules folder (or Class Modules).
  4. Select the module you want to rename. Single-click it in the Project Explorer. Do not double-click unless you also want its code window open — either is fine, but the Properties window must be visible.
  5. Show the Properties window. Press F4, or choose View > Properties Window. It usually appears below the Project Explorer.
  6. Edit the Name property. In the Properties window, click in the field next to (Name) — the top row — and type the new name. Do not include spaces, and do not start with a number. Underscores are allowed.
  7. Press Enter to commit. The Project Explorer updates immediately. If the name is invalid, VBA shows an error and reverts to the old name.
  8. Check for broken references. If other code called the module by name (for example OldName.MyMacro), those calls will now fail. Search the project with Ctrl+F for the old name and update each reference.
  9. Save the workbook. Press Ctrl+S in the VBE or save from Excel. The new module name is stored in the file.

If you are trying to rename a sheet module: you cannot. The names Sheet1, Sheet2, ThisWorkbook and similar are fixed by Excel. To change how a sheet is referred to in code, rename the worksheet tab itself (right-click the tab > Rename), then update any code that used the old sheet name. The module name in the Project Explorer will follow the tab name automatically.

Common Mistakes

  • Looking for a Rename command. Right-clicking a module gives you Insert, Remove, Export, Import and a few others — there is no Rename. The Properties window is the only place to change the name.
  • Using spaces or punctuation. Names such as My Module or Module-1 are rejected. Use letters, digits and underscores, and start with a letter.
  • Renaming a document module. Attempting to change Sheet1 or ThisWorkbook in the Properties window does nothing useful; Excel resets it. Rename the sheet tab instead.
  • Forgetting dependent code. Renaming a module does not update ModuleName.Procedure calls elsewhere. The code compiles but fails at runtime with a “Sub or Function not defined” or “Method or data member not found” error.
  • Not saving as macro-enabled. If the file is saved as .xlsx, macros and module names are stripped on save. Use .xlsm.

Tips

  • Use a consistent prefix such as mod for standard modules and cls for class modules (for example modImport, clsCustomer). This makes the Project Explorer easier to scan.
  • Rename modules before you write lots of code that references them, not after.
  • If you only want to change the caption shown in the VBE, there is no separate caption for modules — the Name property is the only label.
  • Export the module (right-click > Export File) before renaming if you are unsure; you can re-import it if something goes wrong.
  • Keep names under 31 characters to avoid confusion with sheet names and to stay within VBA's identifier limits.

Troubleshooting

  • The Properties window is greyed out or empty. Make sure you have selected the module itself in the Project Explorer, not the workbook node or a folder. Press F4 again after selecting.
  • “Invalid attribute in Sub or Function” or a name error on Enter. The name contains a space, starts with a digit, or duplicates another module in the same project. Module names must be unique within a workbook.
  • The name reverts after saving. The workbook was saved as .xlsx. Save As and choose Excel Macro-Enabled Workbook (*.xlsm).
  • Macros stop working after renaming. Search all code for the old name (Ctrl+F, Current Project) and update references. Also check any Application.Run "OldName.Macro" strings.
  • You renamed a class module and now New OldName fails. Update every Dim x As New OldName declaration to the new name.
  • The project is password-protected. You must unprotect the VBA project (Tools > VBAProject Properties > Protection) before any rename will stick. Only do this on workbooks you own or are authorised to edit.

Frequently Asked Questions

Can I rename a module by right-clicking it?

No. The right-click menu has no Rename option for modules. Use the Properties window (F4) and edit the (Name) field.

Why can't I rename Sheet1 or ThisWorkbook?

Those are document modules tied to actual sheets and the workbook. Their names are controlled by Excel. Rename the worksheet tab instead, and the module name follows.

Does renaming a module break my macros?

Only if other code refers to the module by name, such as OldName.MySub. Procedures called directly from buttons or the Macros dialog keep working because they are found by procedure name, not module name.

Can two modules have the same name?

No. Module names must be unique within a VBA project. If you try to reuse a name, VBA rejects it and keeps the old one.

What characters are allowed in a module name?

Letters, digits and underscores, starting with a letter. Spaces, hyphens and most punctuation are not allowed.

Does the new name carry over to other computers?

Yes, as long as the workbook is saved in a macro-enabled format and the VBA project is not locked. The name is stored inside the file.