Two Levels of Macro Execution

You can run your macros from either the Microsoft Excel window or the Visual Basic Editor window. When you execute the WhatsInACell macro from the VBE screen, Visual Basic executes the macro behind the scenes. You can't see when Visual Basic selects and applies formatting to the text cells or when it inserts three empty rows for the color legend. To watch Visual Basic at work, you must run your macro from the Microsoft Excel window by choosing Tools | Macro, or arrange your screen in such a way that both Microsoft Excel and the Visual Basic windows can be viewed at the same time (see Figure 1-6).

To arrange your screen so that it matches Figure 1-6, perform the following steps:

1. Right-click the empty section of the Windows taskbar. The taskbar is the bottom area of the screen where the Start button is located.

2. From the Windows shortcut menu, select Tile Windows Vertically.

3. Minimize the windows that are not needed, and repeat step 1 above.

EZBE3

l^] File £<¡1 View hielt Fsirrrat Jods Qola ^rvtw He*] - &

l^] File £<¡1 View hielt Fsirrrat Jods Qola ^rvtw He*] - &

■—"A '

B

c

D

E

1

1

Category

Jan

Feb

Mai

13! Oil.

3

Pencils

\2

34

22

6E

4

Pens

10

35

25

74

i

Total

22

SEI

51

142

6

7

a

to

'1

12

13

'4

Ks

IE

Ii1

ta

15

AO

21

22

i« * i *il\5hertW3*ét£/Sheets-j

l«l

1

iJJ

I Microsoft Vis-ual Batic - ChapOlnls - [Modulel (Code)]

£ile £dil. View Jnseit Fflirrat Qcbug B.w> Xools áddHns Window Help - S *

El-M VBAProiett (HhapOl Kls)

j É-S3 Microsoft Excel Objects @ Sheetl (SJieet3) ' ® SheetZ (5heet2) © 5heet3 (Sheet3) : S fhisWorttjook F1 -S5 Modules <£¡ Module)

el Module Alphabetic I Categorized |

el Module Alphabetic I Categorized |

GL

joicnciíil» jJ [WhntstnAC^J

Sub WhalsInACellO T

'WhatsInACeÜ Macro ' ' Macro recordad 5/31/2Cl_ 1 Indícales the contents o " formulas.

3 el eel ion. Special Cells With Selection.Font Name = "Arial* .For>tStyle = "Bold" .Size = 10 Strikethraugh = Fa .Superscript = Fals .Subscript = Faise OutlineFont = Fals .Shadow = False .Underline = xlUnde .Colorindex = 13 End With

R an ge("B6'}. Select Selection.SpecialCells With Selection,Font .Name = "Arial"

Figure 1-6: If you want to watch the execution of your macro from the level of the Visual Basic Editor, you must position the Microsoft Excel and VBE windows side by side.

4. Now that both windows are side by side, click anywhere inside the macro code, and press F5 (or choose Run | Run Sub/UserForm). Now, sit back and watch. Isn't it exciting to see Visual Basic quickly perform the actions you recorded? Later, you will learn how to slow down Visual Basic so that you can watch the execution of your code step by step.

Was this article helpful?

0 0

Post a comment