Table of Contents
In the previous post , we learnt about how to reach VBE through Excel, how to open and close different windows and how to save the macro enabled sheet.
Now the next thing which needs to be learnt is about the different terminology and some more information about procedures and functions, how to insert procedures and functions in Visual Basic for APPLICATIONS etc.
In this article we’ll learn about various terms which will be used over and again in the further articles and learn about how to add a module etc.
Code is done in the CODING WINDOW.
As we are aware that any programming is done with the statements. Same is the case with Visual Basic, we write the code to be performed and executed.
All the code written is stored in the module.
The code is the main content which makes the program execute. The program is executed by compiling the code. If there is any error we need to revisit the code. The program can’t run if the code is having an error.
So our focus will be to do the programming correctly to get the desired result.
Modules are just like a module of the book. A collection of procedures. We store modules in the workbooks. We can always edit them by going to VISUAL BASIC EDITOR.(VBE).
This module contains all the code in the form of procedures.
We’ll see the procedures later in the same article.
ADDING A MODULE
Here are the steps to add modules into workbook.
- Select the project in which the module is to be inserted.
- Go to INSERT MENU and select insert>module.
The same process can be done by RIGHT CLICKING the sheets or project folder and selecting INSERT>MODULE,
USERFORM or class module.
In the same process we can also insert USER FORM (SELF DESIGNED GUI) and class module (If we want to design any class) also.
The picture below shows all the process.
REMOVING A MODULE
If you want to remove the module, follow the following steps:
- Select the module to be removed.
- Go to file.
- Click on Remove …. module. …… will be having the name of the module.
Right click the module and choose remove …….. module.
The procedure is shown in the picture itself.
WHAT ARE PROCEDURES IN VBA
PROCEDURES are the codes which we do in the VBA. These are the sets of statements which are instructions for the Excel to perform.
There are mainly four types of procedures
1. SUB PROCEDURES: Set of simple instructions to be carried out in a sequence.
2. FUNCTION PROCEDURES: A function is a set of procedure which returns a single value or an array. Many functions are builtin in Excel such SUM, SUMIF, VLOOKUP, XLOOKUP etc.
3.DELARATION PROCEDURES: These are the declaration of variable. Variables are the data types of some specific type which we use for holding the values while performing the calculations.
4. PROPERTY PROCEDURES: These are used in the Class modules only.
We’ll discuss only the first three in details in the further articles.
STANDARD FORMATS OF PROCEDURES.
It starts like
statements to be executed
This was a subprocedure.
As soon as we declare this, we will find the name of the subprocedure in the macro list. We can run the code from the macro. It executes the statement line-wise line.
Function in the VBA is written in the following format
Function name_of_function(arguments to be passed)
These are simply declared as
Declaration of the variables.
CLASS MODULE PROCEDURE
It’s done as a proper programming code to control the windows based events for VBA forms. It’ll be discussed later.