Friday, January 1, 2010











VBA for Excel Lesson 1: The Visual Basic Editor in Excel (VBE)
Special note for users of Excel 2007: See how to install the Visual Basic Editor from your Office CD.

For users of Excel 1997 to 2003: The first thing that you need to do is to make sure that the security level of Excel is set at either "Low" or "Medium" so that you can use the macros (VBA procedures) that you develop. See how to do this in lessons 10 on Excel VBA Security.

The VBE is integrated into Excel and you can open it from the Excel menu bar "Tools/Macro/Visual Basic Editor" .

The Visual Basic Editor in Excel (VBE)
Open Excel and on your keyboard click on the "ALT" key (left of the space bar), hold and click on the "F11" key (the F11 key is at the top of your keyboard). Here is the Visual Basic Editor. Click again "ALT/F11" and you are back into Excel.

The Three Windows in the Visual Basic Editor
When you want somebody to do some work for you you open your Email program and you send him a message in a language that he understands (English, Spanish, French...). When you want Excel to do some work for you you open the Visual Basic Editor and you write the instructions in a language that Excel understands VBA ( Visual Basic for Application).

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. When you send the workbook to the "Recycling bin" the VBA procedures are gone.

The Excel Visual Basic Editor
When you work with the VBE there always should be 3 windows showing. The Project window (1), the Code window (2) and the Properties window (3).



If you dot not see these 3 windows on your screen follow the instructions below. Once you have set the three windows properly they will remain in their position when you reopen Excel.

If there are any windows open under the tool bars close them. On the menu bar of the VBE choose "View" and select "Properties Window" . The window can appear minimized, it can be full width at the top of the screen or many other ways. You want it from top to bottom on the right of the screen. To do so click on its blue line at the top, hold and drag it to the bottom right corner. It is now minimized. Click again on its blue header, hold and drag it full left (it will even disappear) toward the vertical middle of the screen. It is now in the following position:



Then go back to the menu bar and select "Project Explorer" . From wherever it is click on its blue header, hold and drag it all the way down in the bottom right corner. It is now free.



Reduce the size of the "Project Explorer" to about the width of the "Properties Window" and one third the height by using the double arrows that appear when you move the mouse over the border of the "Project Explorer" . Click again on its blue header, hold and bring the top left corner of the "Project Explorer" over the top left corner of the "Properties Window" . Then let go.

You now have the "Project Explorer" over the "Properties Windows" in the left part of your screen. The "Code Window" appears when you double click on a sheet name in the "Project Explorer" . You will see later that the " Code Window" also appears when you double click on a userform name or a module name.

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

You can use "ALT/F11" to navigate from Excel to the VBE and back.


--------------------------------------------------------------------------------

Discover More Tips, Ideas and Examples on this Topic
In the complete 33 lessons of the
Downloadable Tutorial on Excel Macros



--------------------------------------------------------------------------------

You will discover much more in the complete lesson 1 that you will find in the downloadable tutorial:

The Visual Basic Editor Menu Bar

There are some very useful menu items that you need to discover in the VBE.



The Visual Basic Editor Toolbars
There are also many icons that will help you do your work more rapidly and more easily.



The Visual Basic Editor Object Browser
You will read about all the VBA words in the Object Browser. You will refresh your memory on things that you do not use often, you will get inspired by bits and pieces of code or you will discover interesting things at random.



The VBA Toolbar (before Excel 2007)

The VBA tool bar in Excel is small but it gives you access to powerful programming tools very easily.



The "Developer" Ribbon (Excel 2007)

In the Developer ribbon in 2007 you will find the same functions as in the VBA toolbar of 2003. Like for all the other ribbons the presentation is different but there are no new functions.




--------------------------------------------------------------------------------

There are three sections in this website and in the downloadable tutorial on VBA for Excel.

Section 1: Excel Macros Programming: 10 lessons
This section is about recording, writing, modifying and testing macros in the Visual Basic Editor. You will learn about security and discover "events" (an event is what starts the macro).
Section 2: Excel VBA Vocabulary: 13 lessons
Developing a macro is like talking with Excel and to do so you need to use a language called VBA. There are over a thousand VBA words but you will really need only 100 to talk with Excel about workbooks, worksheets, cells, databases, loops and to develop simple and powerful macros.
Section 3: Forms and Controls in VBA for Excel: 10 lessons
The form is a small window that allows the user to submit values that will be used by the macro. To these forms you add controls (command buttons, text boxes, list boxes and others).


--------------------------------------------------------------------------------

No comments:

Post a Comment