Understanding the Code Window

The Code window is used for Visual Basic programming as well as for viewing and modifying the code of recorded macros and existing VBA procedures. Each module can be opened in a separate code window. There are several ways to activate the Code window:

■ From the Project Explorer window, choose the appropriate UserForm or module. Then click the View Code button.

At the top of the Code window, there are two drop-down list boxes (Figure 1-20) that allow you to move quickly within the Visual Basic code. In the Object box on the left side of the Code window, you can select the object whose code you want to view. The box on the right side of the Code window lets you quickly choose a particular procedure or event procedure to view. When you open this box, the names of all procedures located in a module are sorted alphabetically. If you select a procedure in the Procedures/Events box, the cursor will jump to the first line of this procedure.

By dragging the split bar (Figure 1-20) down to a selected position in the Code window, you can divide the Code window into two panes (Figure 1-21). You can then view different sections of a long procedure or a different

Figure 1-20: The Visual Basic Code window has several elements that make it easy to locate procedures and review the VBA code.

procedure in each pane. Setting up the Code window for the two-pane display is often used for copying or cutting and pasting sections of code between procedures of the same module. To return to the one-window display, simply drag the split line all the way to the top of the Code window.

At the bottom of the Code window, there are two icons. The Procedure View icon displays only one procedure at a time in the Code window. To select another procedure, use the Procedures/Events box. The Full Module View icon displays all the procedures in the selected module. Use the vertical scroll bar to scroll through the module's code.

The margin indicator bar is used by the Visual Basic Editor to display helpful indicators during editing and debugging. If you'd like to take a quick look at some of these indicators, skim through Chapter 13.

WhatslnACell Macro

Macro recorded E/31/2002 by Julitta Korol

Indicates ihe contents oilhe underlying cells; tsxl. numbsrs, formulas.

Ei e I e ct i on. Sp e c i a IC ells(xlC e I ITy p eConst a nt s 2). Sele ct With Seleclron.Font .Name = "Arlal" .FontSlyfe = "Bold" .Size = 10

.Strikethrough = False

.Colotlndex = 11 End With

Range("C6"). Select

Sslsction.SpeclalCella(*ICelTTypaFoimulae, 23) Select With Selection. Font .Name = "Arial" .FontStyle IfBold" .Size = 10

.Strikelhrough = False

Figure 1-21:

For reviewing longer procedures, you can divide the Code window into two panes.

0 0

Post a comment