Thursday, September 2, 2021

Visual basic interface


Visual basic interface

     Visual Basic is a computer programming language allows the creation of user-defined functions and the automation of specific computer processes and calculations. Users do not have to buy a copy of Visual Basic professional because Visual Basic for Applications is a standard feature of Microsoft Office products. Visual Basic for Applications (VBA) allows users additional customization beyond what is normally available in Microsoft Office products, such as Excel, Access, Word and PowerPoint.

How to open the VBA environment

     
Select the Developer tab from the toolbar at the top of the screen. Then click on the Visual Basic option in the Code group.

Now the Microsoft Visual Basic editor should appear and you can view your VBA code.


Project Explorer


The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's take a few moments to analyze the various sections in the Microsoft Visual Basic window.
The Project Explorer can usually be found in the top left portion of the Microsoft Visual Basic window. It is a hierarchical listing of the objects recognized by VBA.


In this example, there are four Excel objects which represent each sheet and workbook in your Excel file - Sheet1, Sheet2, Sheet3, and ThisWorkbook.
There is also one module called Module1. The VBA code in Module1 can used anywhere in your spreadsheet. Whereas, the code within an Excel object is typically only used by that object.
If the Project Explorer is not visible when you open the Microsoft Visual Basic for Appliations window, you can make it visible by selecting Project Explorer under the View menu.

Properties Window

The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Properties window in the VBA environment.
The Properties window is usually found directly below the Project Explorer in Excel 2010. It displays the properties for the object currently highlighted in the Project Explorer.


In the example above, it is displaying the properties for the module called Module1.
If the Properties Window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Properties Window under the View menu. 

Code Window
The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Code window in the VBA environment. The Code window is usually found to the right of the Project Explorer in Excel 2010. It displays the VBA code for the object currently highlighted in the Project Explorer.


In the example above, it is displaying the VBA code for the module called Module1.

If the Code window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Code under the View menu.
Immediate Window
The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Immediate window in the VBA environment.


In Excel 2010, the Immediate window is usually found below the Code window. It is an essential element of the debugger found within the VBA environment. It lets you:

  • Type code and press ENTER to view the results of the code.
  • When in debug mode, it lets you view the value of a variable in its current state. This will be discussed in the tutorial on Debugging VBA Code.
If the Immediate window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Immediate Window under the View menu.

Watch Window

The Microsoft Visual Basic for Applications window displays your VBA environment in Excel 2010:
Next, let's analyze the Watch window in the VBA environment.


In Excel 2010, the Watch window is usually found below the Code window. It is one of the most valuable tools when debugging in the VBA environment. It lets you:

  • Define and monitor any expression.
  • When in debug mode, it lets you view the value of the watched expression in its current state. This will be discussed in the tutorial on Debugging VBA Code.
If the Watch window is not visible when you open the Microsoft Visual Basic for Applications window, you can make it visible by selecting Watch Window under the View menu.

Data base function

Database function Daverage function      Averages the values in a field (column) of records in a list or database that match conditio...