Program by Levels

 

 

 

 

This is one of the 33 lessons from the
Tutorial on VBA for Excel

Learn More about it


VBA Lesson 1-2: The Project Window in the Visual Basic Editor of Excel

Note: For a better comprehension of the lessons in section 1 on the Visual Basic Editor and the Macro Recorder www.excel-vba.com has created a workbook (vba-tutorial-editor.xls) one of the 25 that are included with the VBA for Excel Desktop Tutorial.

The Project window shows you all the workbooks that are open.

Visual Basic Editor Project Window

If you click on the minus (-) signs in the Project window  you see the objects that are part of the different workbooks (projects). There are Sheets in a workbook, there is always the ThisWorKbook object (in which you store the procedures that you want to start automatically when the workbook is opened) and, there can be Forms (lessons 3-1 to 3-10) and Modules (files in which you write and regroup your VBA procedures (macros)  one or many per module).

In the picture above you can see that the project "Book1.xls" comprises 3 sheets and ThisWorkbook. "excel-visual-basic-editor.xls" has 6  sheets, one userform, two modules plus the "ThisWorkbook" object. If in the project window you double click on a sheet, on ThisWorkbook or on Module1 you will see two things happening. In the "Property window" you see the properties of the selected objects and in the "Code window" you see  the code related to the selected object.

In "excel-visual-basic-editor.xls" you will see that there is code in both modules.

Single click on "modTest" in the Project window and notice that there are 2  procedures in the module. We will test "proVisible" at the end of lesson 4 and we will test  "proTest" in lesson 6

Single click on " Module1" in the project window. There is a recorded macro there that we will be modifying in lesson 9 of this tutorial.

You can add forms and modules to any workbook by right clicking anywhere within one of the projects and select " Insert" in the contextual menu. You can now insert modules and userforms...forget about the Class Module.

Visual Basic Editor Adding Component

Right click within the project "excel-visual-basic-editor.xls" and add a  userform and see what happens.

Visual Basic Editor Adding userform

A form (UserForm2) has been added to the list of objects of the project and the form itself plus the toolbox appear in the code window. If the " Toolbox" window doesn't show use its icon from the toolbar at the top to call it   . You will discover in lessons 3-1 to 3-10 the wonderful world of userforms. You create them to get input from your users.

Double click on "Sheet1" in the project   window and the form disappears. Double click on " UserForm2" in the project   window and the form comes back.

You can copy a module or a userform from one workbook to the other by simply left clicking on it, holding and dragging it to the other project. Try it, drag Module1 of "excel-visual-basic-editor.xls" to " Book1.xls" . By doing this you make all the VBA procedures developed in "excel-visual-basic-editor.xls" part of " Book1.xls" . Do the same with " UserForm2" .

Now go to Excel and close "excel-visual-basic-editor.xls" so that only " Book1.xls" is open.

Select cell "A1" and click on "SHIFT/CTRL/A". The macro from "excel-visual-basic-editor.xls" now works in "Book1.xls" .

Close "Book1.xls" and re-open "excel-visual-basic-editor.xls" . Go to the VBE and let's  discover the other windows.


This is one of the 33 lessons from the
Tutorial on VBA for Excel

Learn More about it

                 
       

 

Developed and Presented by PLI Consultant Inc