VBA stands for Visual Basic for Applications; it is an event driven programming language developed by Microsoft. It is predominantly used with Microsoft office applications like MS-word, MS-Access, and MS-Excel.
A macro is a sequence of key or mouse actions and host commands that you can perform with a single action, such as a keystroke. You can edit an existing macro or create a new macro by selecting Preferences → Macro/Script from the Edit menu
Break mode in VBA is used for debugging and fixing errors. If we need to continue with execution, we should either click on the play button or press F5 or F8. Or we should just end the program's execution and start a fresh run of the code.
Getting started. First, select the Automate tab on the ribbon. This will expose your two primary options in the Scripting Tools group: Record Actions and New Script. To create a new Office Script, press the Record Actions button, then start taking the steps you want to automate.
Print is telling VBA to print that information in the Immediate Window. This can be useful when you want to see the value of a variable in a certain line of your code, without having to store the variable somewhere in the workbook or show it in a message box.
The VBA (Visual Basic Information) have flexible applications, but there is a limitation to a function pointer in VBA. Windows API has inadequate support for function pointers because it has the ability to use the function but not the functional support to call back the function. It has inbuilt support for the call but not for a callback.
“Option Explicit” makes the declaration of variables mandatory. Line explicit function makes the compiler to determine all the variables that are not declared by the dim statement. This command diminishes the problem of type errors significantly. It is used in VBA because it deals with information rich application in which type errors are common. Before starting any, sub-procedures it can be used inside a module.
While declaring a variable (or even a constant) you need to specify the data type. Declaring the data type helps VBA to understand that which type of value you want to store in the variable. Let us say if you want to store a date in the variable as we have done in the previous example, you need to specify the data type as the date.
ByVal: When an argument is passed By Value, the value assigned to the argument is passed to the procedure. And any changes that are made to the argument inside a procedure, it will be lost when the procedure is ends.
ByRef: When an argument is passed By Ref, the actual address assigned to the argument is passed to the procedure. And any changes that are made to the argument inside the procedure will be passed when the procedure ends.
And By Ref is default in VBA.
Code Module: Default Modules which we use to write all procedures and functions
UserForms: UserForms helps to develop GUI (Graphical User Interface) applications.
Class Modules: Class module allows to create new objects and define methods, properties and events. Also, it will allow to enhance the existing objects.
For…. Next loop, Do While…. Loop, Do until Loop, Do….Loop Until..,Do While Not…Loop, While…. Wend loop
UserForm Controls:
Button, Combo Box, Check Box, Spin Button, List Box, Option Button, Group Box, Label, Scroll Bar, etc,.
ActiveX Controls:
Command Button, Combo Box, Check Box, List Box, Text Box, Scroll Bar, Spin Button, Option Button, Label, Image, Toggle Button.
1. On Error Resume Next
2. On Error Goto Err_Lbl
3. On Error Goto 0