When you record a macro, the macro recorder records all the steps in VBA. The Visual Basic Editor (VBE) is the screen where you can edit the recorded macros and add your variables, control structures, and other code that the Macro Recorder cannot record. The Visual Basic Editor is an application for programming with VBA, and all the main Office applications support it.
The Visual Basic Editor provides many features that help you edit code efficiently and accurately. This lesson introduces you to the Visual Basic Editor’s window and how to use it.
Language: English Japanese
1. Open the Visual Basic Editor
Follow the steps below to open the Visual Basic Editor.
Check out Lesson1. Macro and VBA to show the Developer tab.
1 In the Code group on the Developer tab, click Visual Basic.
2 The Visual Basic Editor will be opened.
TIPS
You can also open the Visual Basic Editor by pressing the [ Alt + F11 ] key.
2. The Visual Basic Editor’s main window
The Visual Basic Editor has three main windows.
A The Project Explorer
B The Properties Window
C The Code Window
2-1. The Project Explorer
In the Visual Basic Editor, a workbook is managed as a single “project“. The Project Explorer stores macros, sheets, etc. in a book as “objects” and displays the list of objects in a tree format. The following five objects will be displayed in the tree.
If the Project Explorer is not visible, click on the View tab and select Project Explorer.
Sheets object
Program what you want to execute when the sheet is operated.
Workbook object
Program what you want to execute when the workbook is operated.
Form object
Program what you want to execute on the user form.
Module object
When using Record Macro, macros are recorded in a module. You can program VBA in a module to create a macro. Macros in modules can be executed in each sheet or book without limiting the objects in the Project Explorer.
Class Module object
You can create classes. A class is the formal definition of an object, typically a custom object. By defining classes, you can build your custom objects.
TIPS
When you create a macro, you generally program VBA in a module. This Module is a sheet for programming. If the Visual Basic Editor is the desk for programming, Module is the paper for creating macros.
2-2. The Properties Window
Characteristics of things to be processed, such as color and size, are called “properties“. The Visual Basic Editor provides the Properties window you can use to view and modify the properties of an object in VBA.
If the Properties Window is not visible, click on the View tab and select Properties Window.
2-3. The Code Window
The code for the macro you created is displayed. You will work most of the actual work of editing and testing your macros in the Code Window. If there are multiple macros, “Procedure Separator” will appear between the macros.
Object drop-down list box
The name of the target object of the event procedure that is selected in the Code window will be displayed.
Procedure drop-down list box
The event name of the event procedure that is selected in the Code window will be displayed.
Indicator bar
You can set and release breakpoints by clicking on the indicator bar.
3. Open the macro that you created
Let’s open the macro that you created in Lesson 1 of Macro and VBA.
1 In the Code group on the Developer tab, click Visual Basic.
2 The Visual Basic Editor will be opened.
A module will be automatically created, and the following code will be entered. Since the macro recorder records all the steps in VBA, so unnecessary code will be entered.
In the next lesson, you will learn the basics of VBA and try to create a macro with VBA code.
–