VBA Basic and Advanced Questions and Answers

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:

  1. Standard Module : it is module which can be used to write/record normal code
  2. Class Module : can be used to do object oriented programming by creating objects/functions/properties etc.
  3. Workbook Module: Way of writing or activating event driven programming using ThisWorkbook module.
  4. 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:

  1. Application/Excel
  2. Workbooks
  3. Worksheets/Sheets
  4. 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:

  1. Public : this is the default scope in VBA. When you declare a variable at Module level, it becomes accessible across VBA project.
  2. Private : it is restricted to the declared block (procedure/function/module)

Leave a Reply

Your email address will not be published. Required fields are marked *