Page 39 - Excel Progamming Weekend Crash Course
P. 39
d540629 ch01.qxd 9/2/03 9:27 AM Page 14
14 Friday Evening
Public Sub MyFirstProgram()
Range(“B2”).Select
ActiveCell.Value = InputBox(“Enter value”)
Range(“B3”).Select
ActiveCell.Value = InputBox(“Enter value”)
Range(“B4”).Select
ActiveCell.Value = InputBox(“Enter value”)
Range(“B5”).Select
ActiveCell.Value = InputBox(“Enter value”)
Range(“B6”).Select
ActiveCell.Value = InputBox(“Enter value”)
Range(“B7”).Select
ActiveCell.Formula = “=Sum(B2..B6)”
ActiveWorkbook.SaveAs Filename:=”MyFirstProgram.xls”
End Sub
Running the Program
After the code has been entered, you can run the program and see how it works. Here are
the steps required:
1. Use the Windows taskbar to activate Excel.
2. Press Alt+F8 to open the Macros dialog box, shown in Figure 1-4. (You can also dis-
play this dialog box by selecting Tools ➪ Macro ➪ Macros from the Excel menu.)
Figure 1-4 Selecting the program to run
3. In the Macros dialog box, select Sheet1.MyFirstProgram (this name indicates that
the program is stored in Sheet1); then click the Run button.
4. The program prompts you to enter a value, repeating this action five times.
When the program finishes, your worksheet should look like Figure 1-5 (although you
entered different numbers, of course).