The $60 Download

Excel Tips

VBA Search Index

Excel Table of Contents

 Online Consulting

VBA Table of Contents

 

Discover hundreds of free tips
Click Here to Go to the VBA (macros) Table of Contents
Click Here to Go to the Excel VBA (macros) Index 

  

VBA Chapter 4 of 25: The Visual Basic Editor in Excel

You will develop, test and modify VBA procedures (macros) in the Excel Visual Basic Editor (VBE). It is a very user friendly development environment. The VBA procedures developed in the Excel Visual Basic Editor become part of the workbook in which they are developed and when the workbook is saved the VBA components (macros, modules, userforms. etc.) are saved at the same time.

For a better comprehension of this chapter open "macros-beginners-exercises.xls" AND open a new empty workbook.

Print this page and Open the VBE.

The VBE is integrated into Excel and you can open it from the Excel menu bar "Tools/Macro/Visual Basic Editor". From the VBE you can go back to Excel by clicking on the Excel button at the top/left of its screen . So if the VBA toolbar is visible in Excel (View/Toolbar/VBA) you can navigate from VBE to Excel using the two buttons .

The Excel Visual Basic Editor

When you work with the VBE there always should be 3 windows that are open in it. The Project window (1), the Property window (2) and the Code window (3).

On the menu bar of the VBE choose "View" and select "Project Explorer" and the Project window opens. Then go back to the menu bar and select "Properties Window" and the Properties widow opens below the Project window. You don't call the Code window from the menu bar. It opens when you double click on any element of a project in the Project window. It shows the procedure that have been saved within the selected object (sheets, modules, ThisWorkbook, userForms).

You can resize the 3 windows by placing the cursor over the borders (*) and dragging them right, left, up or down.

The VBE Menu Bar

Here is the menu bar of the Visual Basic Editor. There are just a few functions that you will use and here they are.

At the very beginning of you programming career you will go to the "View" item to select the Project Explorer, the Properties window, the Edit Toolbar and the Standard Toolbar. You should never have to go back there ever.

Once in a while you will be using "Debug/Clear All Breakpoints" to remove the breakpoints that you have set. You will also go to "Tools/VBAProject Properties/Protection" to protect you VBA code with a password.

You won't really be using anything else from the menu bar.

The VBE Toolbars

Here are the two toolbars that should always be visible at the top of the VBE. The "Standard" toolbar (top) and the "Edit" toolbar (bottom).

From the Standard toolbar you will be using the Undo/Redo arrows   like you do in Excel to correct an error that you have just made while writing in the code window.

You will also use the "Run" arrow to start a procedure. You first click within the procedure in the code window and you click on the blue arrow of the toolbar.

You will use the object browser to find objects, methods and properties as explained below.

Finally if you click anywhere in the code, this tool will tell you on what line you are. So if you are talking with somebody about your code on the phone you can tell your correspondent to select the same line.

From the Edit toolbar you will be using two tools. First the tool that allows you to outlines lines or segments of your code to make it clearer to read . You will also use the comments tool that automatically adds apostrophes to the line or the lines that you have selected. Adding an apostrophe to a line transforms it into a comment that is not executed. The more comment lines the easier you or the ones that will follow you will be able to read and understand you code. 

The VBE Object Browser

So when you click on the icon for the object browser the following window appears covering the whole code window.  When the window is open enter a word in the text box beside the binoculars and the search results appear in the "Search Results" window. Select one of the line in this window and click on the F1 key. The help window opens and you get all kinds of information on the topic that you have chosen. To close the object browser window  just click on the X (top/right) and the code you were working on comes back.

 

In the sub-chapters (4A, 4B and 4C) you will discover the Project Window, the Properties Window and the Code Window.

In the next steps we will see how to create, test and modify VBA procedures in the Visual Basic Editor. You will specially enjoy the approach where you test your procedure step by step while seeing it at work in your Excel spreadsheet on the same screen.

  

More on VBA and Excel

Here are 40 Excel downloadable spreadsheets

Short and well explained examples
Simple ways of doing great things

 

Click here to send your comments

 

The $60 Download

VBA for Excel Tutorial

VBA Search Index

Excel Table of Contents

VBA and Excel Consultant

VBA Table of Contents