The Code  Window in the Visual Basic Editor of Excel

    

613-749-4695 (Peter)
[email protected]

Home Page

Tips and Ideas on Excel
Table of Contents on Excel

Tips and Ideas on Macros
Table of Contents on VBA

Quick Links

 

VBA Chapter 3C of 24: The Code  Window in the Visual Basic Editor of Excel

Note: The images and the text below refer to the workbook "vba-tutorial-editor.xls"

NOTE: You cannot change the font or its color in the code window. You input appears in black, comments appear in green, reserved words in blue and when you make a mistake the color of the font turns to red.

NOTE: The wheel of the mouse doesn't work in the Visual Basic Editor

The picture below shows you what you should see in the code window if you double click on Module1 of "vba-tutorial-editor.xls" in the project window. There is only one VBA procedure in Module 1 and it is named "Macro1" . It is a procedure that has been recorded.

In the window below you see the code created with the Macro Recorder in "vba-tutorial-editor.xls" .

Visual Basic Editor: code window

In the code window there is a main window in which appears the code. At the top there are two drop-down lists.

If there were many procedures in the module you could use the drop-down list at the top right ("Declarations") to get to the other procedures.

When you select a module in the Project window (double click) the right drop down list shows you all the procedures in the module and the left DDList is useless for modules. You will use this DDList when you start developing VBA procedures for userforms and controls or when you develop procedures triggered by an event related to the worksheet or the workbook.

When  you select a worksheet in the Project window (double click) the left DDList of the Code window offers you two values (General and Worksheet). When  you select "Worksheet" in the left  DDList the right DDList offers you the 9  VBA events related to the sheet. Select an event and the VBE creates the first and last line of a procedure in the Code window. You then develop your procedure between  these lines. If you don't need to develop a procedure for this event erase the two lines of code.

When  you select a "ThisWorkbook"   in the Project window (double click) the left DDList of the Code window offers you two values (General and Workbook). When  you select "Workbook" in the left  DDList the right DDList offers you the 28 VBA events related to the workbook. Select an event and the VBE creates the first and last line of a procedure in the Code window. You then develop your procedure between  these lines. If you don't need to develop a procedure for this event erase the two lines of code.

When  you double click on a userform  in the Project window the userform appears. Double click on the userform itself or any of the controls   and   the left DDList of the Code window offers you many values. You will see the userform and the list of controls on the userform. Depending on the element that you choose you will find in the right DDList the events related to the element. Select an event and the VBE creates the first and last line of a procedure in the Code window. You then develop your procedure between  these lines. If you don't need to develop a procedure for this event erase the two lines of code.

You click within one of the procedure and you go to the "Run" icon of the toolbar  Run and the procedure is executed. To stop the execution of a VBA procedure at any time you click (repeatedly) on the "Esc" key.

When you want to stop the execution while testing step by step (using the "F8" key) you click on the "Reset" icon of the toolbar  Reset.

You will create you first VBA procedure in this window in chapter 4 and you will use these tips when you  test your VBA procedures in chapter 5.

 

Next Chapter: Developing Macros in Excel

VBA Table of Contents
or use the quick links below

 

Discover Even More in 50 Excel spreadsheets

 

    

613-749-4695 (Peter)
[email protected]

Home Page

Tips and Ideas on Excel
Table of Contents on Excel

Tips and Ideas on Macros
Table of Contents on VBA

Quick Links

The Code  Window in the Visual Basic Editor of Excel