VBA Module | Insert, Remove, Restore, and BackUp

Last Updated: June 27, 2023
puneet-gogia-excel-champs

- Written by Puneet

What is VBA Module

VBA module is a “.bcf” extension file that holds the code in the visual basic editor. Each module has its own code window where you can write. You can insert a new module, delete, backup, and import it. In simple words, it’s like a text file that you open in the 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 Window 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 the Insert and click on the “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 the module to insert it.

When you insert a new module, VBA creates a separate folder 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, you need to confirm if you wish to back up the module before deleting it.
  4. In the end, click on “Yes” to delete it.

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

It’s a smart way to remind you to get the backup of 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.

As I said earlier, you can save a module as a “.bcf” file and import it in the future or some other Excel file.

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 slight difference between both modules. 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.