Home » VBA Interview Questions and Answers

VBA Interview Questions and Answers

by Online Tutorials Library

VBA interview questions

Data analysis is one of the renowned job posts these days. VBA is a great tool that helps automate common repetitive tasks daily, weekly, or monthly by running the macro. Therefore, to apply for the Business data analysis or VBA developer post, you may require to confront the face-to-face interview round.

VBA interview questions

In this tutorial, we will cover the most commonly asked Fundamental and Advanced VBA Interview Questions that can be useful for Freshers and Experienced VBA Developers.

1) Define macros. What is the advantage of using Macros?

A VBA macro is a set of instructions (or code) stored in the Visual Basic module in a VBA Editor. The VBA Macros are written in a module. To insert a module go the VBA editor and click on Insert ->Module

By running VBA macro, the excel users can automate common repetitive tasks daily weekly. Therefore using macros can save your time, improve productivity, and deliver on time to clients.


2) Define the basic object model of Excel?

Following is the basic Object model of Excel.

Click on Application -> Workbooks -> Worksheets -> Range / Chart


3) What is the quickest way to open the VBA editor screen?

The easy and fastest way to go to the Visual Basic editor window is by using the keyboard shortcut i.e., ‘Alt + F11’


4) What do you understand by the term ‘Option Explicit’?

Option Explicit is used in VBA to force the variables to be declared before using the variable. It helps the VBA developers to dodge the type errors and create a bug free code.


5) What are the types of core Modules present in Visual Basic Editor?

There are three different modules available in VBE:

  1. Class Module: These are default modules commonly used to write functions.
  2. UserForms: They help to design and develop GUI applications.
  3. Class Modules: They helps the user to create new objects, methos, procedures and events.

6) Is it possible to run the macros automatically while opening a worksheet in Excel VBA? IS yes, how is it?

Yes, by using the VBA macros we can automatically open a worksheet in Excel. For execute the same we will use the Workbook_Open() Event to run macros.

Following are the steps to run Workbook_Open() Event in VBA Excel:

  1. Click Alt+F11 to open the VBA Editor.
  2. Go to the Project Explorer and select the ‘ThisWorkbook’.
  3. You will see two drop down lists in the right panel of the pane.
  4. From the first drop down select the ‘Workbook’ option and from the second drop down choose the ‘Open’ option.
  5. In the editor window, you will see the below given code.
  1. Write the VBA macros in-between the above lines to run the macros automatically while opening a worksheet in Excel VBA.
  2. Save and close the workbook
  3. Reopen the same workbook to test the created macro.

Example


7) In VBA, how many scope variables are there?

In VBA editor, there exists different levels of scope variables. Though we can define the variable in three levels that are as follows:

  • Local Level: The Local Level variables are defined with a DIM statement in a procedure or function.
  • Module Level: The Module level scope variables are defined with the DIM keywords on top of a VBA code. The special thing about these variables is that they can be accessed in the entire module.
  • Global Level: The Global Level variables are defined using a Public keyword at the top of your VBA programming module. They can be accessed anywhere in the entire VBA project.

8) Mentions the steps to create object Variable for workbook, worksheet, etc.?

We can create object variable and late it can be used in the entire macro.

Following is the VBA macro to create object for workbook, worksheet, etc.


9) What is an Array? How will you create or define array in VBA?

An array is a set of variables that contains data of similar data type. They are used to refer to a specific array value by using array name and the index number.

We can create and define size of an array variable in the following way.

Syntax

Example:

In the above procedure ‘arrVal’ is an array name and ‘5’ represents the array size.


10) How do I stop recording macro?

Below given are the steps to stop recording macro in your active Excel workbook:

Step 1: Open your Excel workbook. Click on the ‘Developer tab’ located in the main ribbon menu of Excel window.

Step 2: Click on ‘Stop Recording’ button to stop from the recording your active macro.


11) How do I delete macros from the workbook?

Please find the following steps to delete macros from the workbook.

Step 1: Open your Excel workbook. Click on the ‘Developer tab’ located in the main ribbon menu of Excel window.

Step 2: Next, click on the Macros button to check all the existing macros present in your Excel workbook.

Step 3: It will open the Macro dialog box on the screen.

Step 4: Select the macro name which you want to delete, and then click on ‘Delete’ command button.

Step 5: The confirmation dialog box will appear. Click on Ok to confirm the delete of the selected macro.


12) What are the different ways to speed up the VBA macro?

This is one of the most common VBA questions frequently asked in the interview round. By asking it, the interviewer wants to understand your real experience in VBA coding and how to take care of coding techniques.

While writing VBA code, we have several best practices to follow. We can speed up the execution of VBA macros by following the given techniques.

  1. Declare your variables without using the ‘Variant’ Data Type. As it takes more space.
  2. Always remember to turn Off the ‘Screen Updating’
  3. Turn Off the automatic calculations
  4. Always remember to disable the Events
  5. Use With Statement
  6. Use the vbNullString instead of “”.
  7. Release all the memory objects at the end of the procedure.

13) What are the different built-in Class modules available in VBA:

The different built-in classes are as follows:

  1. Workbook modules
  2. Worksheet modules

Microsoft Access VBA Interview Questions

1) Write a VBA code to create a table in the required database.

Following is the VBA macro to create a table in the required database:


2) Write VBA macro to quickly insert records in the MS Access database table.

Following is the VBA macro to quickly insert records in the MS Access database table:


3) Write a VBA code to update an existing record in the database table.

Following is the VBA macro to update an existing record in the Ms Access database table:


4) Write a VBA macro to delete records present in the Ms Access database.

Following is the VBA macro to delete records present in the Ms Access database:


5) Write a VBA code to export the Ms Access Table to Excel.

Following is the VBA macro to export the Ms Access Table to Excel.


6) Write a VBA code to change the existing table name in the Ms Access database.

Following is the VBA macro code to change the existing table name in the Ms Access Database:


Microsoft Word VBA Interview Questions

1) Can you open a new document in word using VBA procedure?

Below given is the VBA macro code to open a new document in word:


2) Write a VBA macro to quickly open a new work document from the existing word document.

Below given is the VBA macro to quickly open a new work document from the existing word document:


3) Write a VBA macro to create an existing word document as a read only document.

Below given is the VBA macro to create an existing word document as a read only document:


4) Write a VBA macro to SaveAs a word document if already not saved.

Below given is the VBA macro to SaveAs a word document if already not saved:


5) Write a VBA macro to quickly select the current line in a MS word document.

Below given is the VBA snippet to quickly select the current line in a Ms word document:


6) Write a VBA macro to quickly select the entire Ms word document.

Below given is the VBA snippet to quickly select the entire Ms word document:


7) Write a VBA Macro to quickly change (increase or decrease) the font size of third paragraph in a Ms word file.

Following is the VBA macro to quickly change the font size of the third paragraph of your word document file.


Microsoft Outlook VBA Interview Questions

1) Write the VBA code to sent an email using Outlook?

Below given is the VBA code to send an email using Outlook:


2) Can we also add an attachment to an email in Microsoft Outlook using VBA? If yes, write the VBA code.

Following is the VBA macro to quickly add an attachment to an email using Microsoft Outlook.


3) Write a VBA macro to add attachment and send an email simultaneously using Microsoft Outlook.

Following is the VBA snippet to add attachment and send an email simultaneously using Ms Outlook.


4) Can we also create a Task in Ms Outlook using VBA macro?

Yes, we can create a Task in Ms Outlook using VBA macros. Following is the VBA snippet to do so.


Microsoft PowerPoint VBA Interview Questions

1) Can you automate a new PowerPoint Presentation using VBA macros? If yes, write the VBA code.

Yes, VBA can also automate the various PowerPoint tasks. Following is the VBA snippet to create a new PowerPoint Presentation:


2) Write a VBA macro to add new slide in a PowerPoint Presentation.

Following is the VBA snippet to add a new slide in a PowerPoint Presentation:

‘OR


3) Write a VBA macro create a new PowerPoint Presentation and later save it in your files.

Following is the VBA macro to create and save a PowerPoint Presentation:


4) Can you move a PPT slide from one position 1 to 4 in a PowerPoint Presentation?

Yes, using VBA macro we can move a PPT slide from one position 1 to 4 in a PowerPoint Presentation. Refer to the following macro:


5) Write a VBA code, to start the PowerPoint slide show.

Following is the VBA snippet to start the PowerPoint slide show:


You may also like