Skip to content
Related Articles

Related Articles

How to Delete a Module in Excel VBA?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 07 Mar, 2022

Have you ever seen a text file in a notepad or a source code file in visual studio code? These all are just basic files where you can write some code or information. Similarly, we have modules in excel, each module has its code window, where you can write some code and allow it to automate your repetitive tasks. There can be multiple modules. We can create, rename or delete a module in just a few mouse clicks. In this article, we will learn how to create and delete a module in excel VBA. 

Module and its types

A module is a set of instructions written in a VBA editor. There are broadly 5 types of modules in VBA: 

  1. General-Purpose Module: It is the simplest type of module. If we record a macro that will get stored in a module. This is called a general-purpose module. We can simply write code in the VBA editor also.
  2. Workbook Module: Workbook module handles the events happening at a workbook level. For example, opening, closing or renaming a workbook.
  3. Worksheet Module: The worksheet module is driven by the events happening at the worksheet level. For example, activating a worksheet or flipping between different worksheets. Automating the task such as merging the worksheets. 
  4. Userform Module: Userform Module is a way to input a piece of information from the user.  It is one of the most useful tools of VBA. 
  5. Class Module: It’s similar to the classes in other languages. We create our objects. VBA has built-in objects such as the Collection, Workbook, etc. The inheritance in VBA is minimal and much more restricted than in other languages. 

Creating a VBA module

Following are the steps to create a VBA module,

Step 1: Go to Developer Tab, and select Visual Basic in the menu bar. 

Selecting-visual-basic

Step 2: A VBA editor appears. We can see the information on all the worksheets and workbooks in the editor tab. 

Workbook-and-worksheets

Step 3: Go to Insert Tab and select Module

Selecting-module

Step 4: A module name module1 is created.

Module-1-created

Deleting a VBA module

Following are the steps to delete a VBA module,

Step 1:  Given 3 modules name module1, module2, and module3. Delete module3 from the Modules. 

Deleting-module-3

Step 2: Right-click on module3 and click on Remove module3. A dialogue box appears. 

Removing-module

Step 3: The dialogue box tells whether you want to export the given module or not. If you, do not want to save the module on your PC, then click on No.

Dialogue-box

Step 4: Module3 has been deleted from the VBA editor. 

Module3-deleted

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!