Basic Q&A
Q. VBA stands for?
Ans: Visual Basic for Applications
Q. What is VBA?
Ans: VBA (Visual Basic for Applications) is a scripting language. It can be used to automate most of the Microsoft Office Applications like Excel, Word, PowerPoint, MS Access, Outlook etc.
Q. Types of available modules in VBA
VBA contains four types of Modules:
- Standard Module : it is module which can be used to write/record normal code
- Class Module : can be used to do object oriented programming by creating objects/functions/properties etc.
- Workbook Module: Way of writing or activating event driven programming using ThisWorkbook module.
- Sheet Module: Writing the code inside Sheet or activating event driven programming.
Q. What is the difference between VBA and VBE?
Ans: VBA stands for Visual Basic for Applications and VBE stands for Visual Basic Editor. VBA is a scripting environment helps automating the Excel Objects like Workbook, Sheets, Charts, Range etc. VBE provides more structured programming where you can write code to find number of Modules used in your program, or list all the modules’ name, or list all procedures/functions written in a module etc.
Q. Explain Excel Object Model
Following is the Excel Object hierarchy:
- Application/Excel
- Workbooks
- Worksheets/Sheets
- Range/Cells
Q. What is the difference between Procedure and Function in VBA?
Ans: Procedure refers to a set of code and not necessarily returns a value. Where a function always returns a value.
Q. What is call by value (ByVal) and call by reference (ByRef) in VBA and what is default?
Ans: We can pass arguments to a procedure (function or sub routine) by reference or by value. By default, VBA passes arguments by reference (ByRef).
Q. Explain object/variable scoping in VBA
Ans: VBA has two types of scopes:
- Public : this is the default scope in VBA. When you declare a variable at Module level, it becomes accessible across VBA project.
- Private : it is restricted to the declared block (procedure/function/module)