Navigating Projects with the Project Explorer Window

The Project window (aka Project Explorer), shown in Figure 2.1, doesn't look like it has much to offer. This is because I only have one workbook open and have yet to insert any forms, modules, or class modules. Figure 2.3 shows a more realistic example of the Project Explorer.

In Figure 2.3, three workbooks are open. The Project Explorer considers each to be a separate project. All of the projects in this figure have the default project name of VBAProject followed by the name of the workbook in parentheses. You can change the name of a project by selecting the project in the Project Explorer and then changing the name associated with the selected project in the Properties window.

By default, the Project Explorer groups like objects together in folders. Depending on the project, you may have up to four kinds of objects associated with a project.

Microsoft Excel objects Each worksheet in a workbook is considered an Excel object. Also an object called ThisWorkbook represents the workbook as a whole. Because a workbook must have at least one worksheet, you'll always find at least two items in this folder, one worksheet object and the ThisWorkbook object.

Figure 2.3

A busy Project Explorer

Figure 2.3

A busy Project Explorer

Projekt Explorer Excel 2003

Forms Forms represent user forms that can be added to a project. We will discuss user forms in detail in Chapter 20.

Modules A module is a container for the procedures you write. When you start writing code, you'll begin by inserting a module into the project.

Class modules Class modules are a special kind of module that allows you to develop your own custom objects. I'll discuss this in great detail in Chapter 11.

You can also view the various objects in a project without the folders, as shown in the following graphic, by clicking the tool button in the Project Explorer toolbar. The ToolTip for this icon is Toggle Folders.

Project - VBAProject


1 LJ J ^


- ^ VBAProject (Book2)


»¿JvBAProject (CheckTrak Loader.Hls)

»it basConstants




fflj Settings (Settings)

IS] Sheet4 (Menu)

® ThisWorfcbook

- VBAProject (OTA Rcports,nls)



n&i basBusLineAUDetal

•«1 bas6usLjneAU5umiwy







The Project Explorer toolbar also includes two other tool buttons: one labeled View Code (the button on the left) and another labeled View Object (the button on the right).

All four kinds of objects associated with a project have a VBA code window associated with them. You can view the code window associated with an object by selecting the object in the Project Explorer and clicking the View Code button. Microsoft Excel Objects and Forms also have a viewable object associated with them. If you select a worksheet object and click View Object, for example, you'll be transported back to the main Excel window, which will have the appropriate worksheet displayed. Forms are slightly different. Forms have a visual design window associated with them. This window is what is displayed when you use View Object on a form object.

NOTE As with just about anything, when it comes to performing various tasks in the VBE, you can achieve the same result in more than one way. For example, you can also view code by performing one of the following three actions: (1) right-clicking the object to display the context menu and choosing View Code, (2) selecting the object and choosing the View ^ Code menu item, or (3) selecting the object and pressing F7. I'll present the various flavors of using the context menu, the main menu, or shortcut keys throughout the book. Shortcut keys are my favorite because they are extremely efficient when com-pared to other methods.

Don't Miss This Overlooked Tip

Now that I have your attention, you have got to know one other thing about the Project Explorer that many people overlook; this can be a real timesaver. As you start developing a critical mass of code, you'll occasionally want to transfer forms, modules, or class modules between projects. You can perform this action very quickly using the Project Explorer. Simply open the workbook that contains the object you want to transfer and any workbooks that you want to transfer the object to, and then drag and drop the object into the project that you want to transfer it to. This doesn't remove the object from the original project; it just copies it into the destination project. Though it would be nice, you can't transfer worksheets between workbooks in this manner.

TIP You can drag and drop forms, modules, and class modules between projects.

0 0

Post a comment