30 Advanced Excel Tips for 2026

Excel Champs / VBA / VBA Module | Insert, Remove, Restore, and BackUp
By Puneet Gogia (Microsoft MVP)

VBA Module | Insert, Remove, Restore, and BackUp

30+ Advanced Excel Tips for 2026

No spam. Only Excel Stuff. God Promise. 😊

To add a module, open the Visual Basic Editor (Alt + F11), select your workbook in the Project Explorer (Ctrl + R) and go to Insert → Module. Write or paste your macros in the code window that opens. Save the workbook as .xlsm, or the module won’t be saved with it.

Use a standard module, the kind Insert → Module creates, for ordinary macros and for functions you want to use in cells. Code that responds to events goes in that object’s own module: Worksheet_Change in the sheet’s module, and Workbook_Open in ThisWorkbook. Class modules define your own objects.

To rename a module, select it and change (Name) in the Properties window (F4). Names can’t contain spaces, and they shouldn’t match the name of a procedure in the project, or calls to that procedure stop working.

To remove a module, right-click it and choose Remove. Click Yes when asked whether to export it first if you want a backup. To move code between workbooks, right-click the module and choose Export File, which saves a plain-text .bas file (.cls for class modules, .frm for UserForms), then use File → Import File in the other workbook.

What is VBA Module

A VBA module is a container (saved as a “.bas” file when you export it) that holds the code in the visual basic editor. Each module has its own code window where you can write code. You can insert a new module, delete it, back it up, and import it. In simple words, it’s like a text file that you open in Notepad.

In this tutorial, we will learn all about using a module in VBA.

Insert a VBA Module

  1. First of all, open the Project Explorer (Ctrl + R) if it’s not there already.
  2. Next, right-click on the project (Excel File) in which you want to insert a module.
  3. After that, go to Insert and click on “Module”.
  4. Once you do that, you will instantly get a new module and can open its code window to write the code.
insert-a-vba-module

You can also go to the Insert menu and then click Module to insert it.

When you insert a new module, VBA creates a separate folder (Modules) for all the modules that you have in the project.

Delete a VBA Module

  1. Click on the project from which you want to delete a module.
  2. Now right-click on the module that you want to delete and click “Remove”.
  3. After that, VBA asks if you want to export (back up) the module before removing it.
  4. In the end, click “No” to delete it without a backup, or “Yes” to save a copy first and then delete it.

There’s one thing that you need to know here: when you click on the Remove option, it asks if you want to back up your module before removing it.

It’s a smart way to remind you to back up the module.

Export and Import a VBA Module

You can also import and export a module from one Excel file to another instead of copy-pasting the codes. This is one of the best ways to share your codes with others. When you right-click on a module, you have both options there (Export File and Import File).

As I said earlier, you can save a module as a “.bas” file and import it in the future or into some other Excel file. You can also use File > Export File (Ctrl + E) and File > Import File (Ctrl + M) in the Visual Basic Editor.

Quick Tip: If you want to copy an entire module to a different project whose Excel file is open at the time, drag and drop that module to the project where you want to copy it.

Normal VBA Modules Vs. Class Modules

When you insert a new module, you can see an option to insert a class module. But there’s a big difference between the two. As you have understood all about the standard modules, class modules are special modules that can help you create your custom objects. You can also define methods, properties, and events for those objects. And when you create a new object from the class module, you can refer to it from the standard module as well.

Types of Modules in VBA

In a VBA project, you will find four types of modules, and each one has its own job:

  • Standard module: The one you insert from Insert > Module. This is where you write your macros and custom functions. A custom function only works in a worksheet when it’s in a standard module.
  • Sheet and ThisWorkbook modules: Each worksheet and the workbook have their own module (under Microsoft Excel Objects). You use these for event codes, like a code that runs when you change a cell or open the workbook.
  • Class module: For creating your own objects (more on this below).
  • UserForm module: Holds the code behind a UserForm and its controls.

Rename a VBA Module

  1. First of all, select the module in the Project Explorer.
  2. After that, open the Properties window (F4) if it’s not there already.
  3. Next, click in the (Name) box and type the new name.
  4. In the end, press Enter to apply the name.

A module name must start with a letter and can’t have spaces or most special characters (an underscore is fine). Also, don’t give a module the same name as a macro in it; that can confuse VBA when you call the macro.

What to Write at the Top of a Module

The area at the top of a module, before the first procedure, is called the Declarations section. Here you can add Option Explicit, which makes you declare every variable before you use it, and the variables that you want to use in all the procedures of the module:

Option Explicit

Dim counter As Long ' all procedures in this module can use it
Public userName As String ' all modules in the project can use it

Sub AddOne()
counter = counter + 1
MsgBox counter
End Sub

To add Option Explicit to every new module automatically, go to Tools > Options in the Visual Basic Editor and tick Require Variable Declaration.

Frequently Asked Questions

What file extension does an exported module have?

A standard module exports as a .bas file, a class module as a .cls file, and a UserForm as a .frm file (with a .frx file that holds its controls). You can open a .bas file in Notepad to see the code.

Can I use a macro from one module in another module?

Yes. A procedure is Public by default, so you can call it from any module in the same project. If you declare it as Private, only the procedures in the same module can use it.

Why don’t I see my module after I close the file?

The module is saved inside the workbook, so you need to save the file as an Excel Macro-Enabled Workbook (.xlsm). If you save it as .xlsx, Excel removes all the modules and their code.

Puneet Gogia

Written by

Puneet Gogia

Microsoft MVP — Excel · Founder, Excel Champs

Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.

3M+ readers helped
1,000+ tutorials written
Since 2015 teaching Excel