<p style="MARGIN: 0px">Contents</p> <p style="MARGIN: 0px">1 If You’ve Never Programmed Before 1</p> <p style="MARGIN: 0px">1.1 The “Idea” of a Program 2</p> <p style="MARGIN: 0px">1.2 The Concept of Assignment 3</p> <p style="MARGIN: 0px">1.3 Decisions and Loops 4</p> <p style="MARGIN: 0px">1.3.1 Decisions 5</p> <p style="MARGIN: 0px">1.3.2 Loops 5</p> <p style="MARGIN: 0px">1.4 A Simple Example 6</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">2 Overview of VBA for Excel 8</p> <p style="MARGIN: 0px">2.1 The Excel/VBA Environment 9</p> <p style="MARGIN: 0px">2.2 An Excel Interface and a VBA Macro Program 9</p> <p style="MARGIN: 0px">2.2.1 Hands-on Exercise: A Simple Addition Program 10</p> <p style="MARGIN: 0px">2.3 Other Ways to Obtain and Display Information 16</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">3 Recording Macros 20</p> <p style="MARGIN: 0px">3.1 Macro Recording 21</p> <p style="MARGIN: 0px">3.1.1 Hands-on Exercise: Macro Recording to Format a Range of Cells 21</p> <p style="MARGIN: 0px">3.2 Absolute and Relative References 24</p> <p style="MARGIN: 0px">3.2.1 Hands-on Exercise: Absolute versus Relative Recording Mode 24</p> <p style="MARGIN: 0px">3.3 Using Macro Recording to Learn about VBA 27</p> <p style="MARGIN: 0px">3.3.1 Hands-on Exercise: Using a Macro Recording to Learn How to Count</p> <p style="MARGIN: 0px">Data 27</p> <p style="MARGIN: 0px">3.4 What Keyboard Macros Can’t Do 29</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">4 Customized Worksheet Functions 31</p> <p style="MARGIN: 0px">4.1 The “Idea” of a Function 32</p> <p style="MARGIN: 0px">4.2 Worksheet Function Macros 33</p> <p style="MARGIN: 0px">4.2.1 Hands-on Exercise: A Simple Worksheet Function Macro 33</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">5 Modular Programming 39</p> <p style="MARGIN: 0px">5.1 Sub Procedures 40</p> <p style="MARGIN: 0px">5.1.1 Hands-on Exercise: The Kick Calculator 41</p> <p style="MARGIN: 0px">5.2 Function Procedures 46</p> <p style="MARGIN: 0px">5.3 More about Procedure Arguments 47</p> <p style="MARGIN: 0px">5.3.1 Hands-on Exercise: The Behavior of the Parameter List 48</p> <p style="MARGIN: 0px">5.4 Passing by Value or by Reference 50</p> <p style="MARGIN: 0px">5.4.1 Hands-on Exercise: Passing by Value or by Reference 51</p> <p style="MARGIN: 0px">5.5 Static Variables 52</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">6 Object-oriented Programming 55</p> <p style="MARGIN: 0px">6.1 Objects, Properties, Methods, and Collections 56</p> <p style="MARGIN: 0px">6.1.1 Hands-on Exercise: OOP and a Recorded Macro 57</p> <p style="MARGIN: 0px">6.2 Using Oop for Input/Output 61</p> <p style="MARGIN: 0px">6.3 Learning More About Oop 62</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">7 Debugging and Testing 65</p> <p style="MARGIN: 0px">7.1 Debugging 66</p> <p style="MARGIN: 0px">7.2 The VBA Help Facility 66</p> <p style="MARGIN: 0px">7.2.1 Help Menu 66</p> <p style="MARGIN: 0px">7.2.2 Context-Sensitive Help and the F1 Key 68</p> <p style="MARGIN: 0px">7.2.3 Accessing Help from Error Messages 69</p> <p style="MARGIN: 0px">7.3 Built-in Debugging Capabilities 69</p> <p style="MARGIN: 0px">7.3.1 Passive Debugging: VBA Error Messages 69</p> <p style="MARGIN: 0px">7.3.2 Active Debugging 71</p> <p style="MARGIN: 0px">7.3.3 Hands-on Exercise: The VBA Debugger 72</p> <p style="MARGIN: 0px">7.4 Testing 73</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">8 Data Typing And Variable Scope 76</p> <p style="MARGIN: 0px">8.1 Data Types 77</p> <p style="MARGIN: 0px">8.1.1 Numeric Information 77</p> <p style="MARGIN: 0px">8.1.2 Character, or “String,” Information 79</p> <p style="MARGIN: 0px">8.1.3 Logical, or “Boolean,” Information 79</p> <p style="MARGIN: 0px">8.2 Type Declaration 80</p> <p style="MARGIN: 0px">8.2.1 Variant Data Type 80</p> <p style="MARGIN: 0px">8.2.2 The Dim Statement 81</p> <p style="MARGIN: 0px">8.2.3 Option Explicit 82</p> <p style="MARGIN: 0px">8.2.4 Hands-on Exercise: Run Time for Single and Double Precision 83</p> <p style="MARGIN: 0px">8.2.5 Type Declaration Characters 84</p> <p style="MARGIN: 0px">8.2.6 The Const Statement 85</p> <p style="MARGIN: 0px">8.3 Variable Scope and Lifetime 85</p> <p style="MARGIN: 0px">8.3.1 The Parameter List 86</p> <p style="MARGIN: 0px">8.3.2 Scope and Declaration 87</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">9 Computations 90</p> <p style="MARGIN: 0px">9.1 Computations 91</p> <p style="MARGIN: 0px">9.1.1 Operator Priority 91</p> <p style="MARGIN: 0px">9.1.2 Left to Right 92</p> <p style="MARGIN: 0px">9.2 Built-in Numeric Functions 93</p> <p style="MARGIN: 0px">9.2.1 Accessing Excel Functions from VBA 94</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">10 Strings and Dialog Boxes 99</p> <p style="MARGIN: 0px">10.1 String Functions and Manipulations 100</p> <p style="MARGIN: 0px">10.1.1 Concatenating and Parsing Strings 100</p> <p style="MARGIN: 0px">10.1.2 LCase and UCase 101</p> <p style="MARGIN: 0px">10.2 Message Boxes 103</p> <p style="MARGIN: 0px">10.2.1 Buttons 105</p> <p style="MARGIN: 0px">10.3 Input Boxes 107</p> <p style="MARGIN: 0px">10.3.1 Hands-on Exercise: Data Typing, String Functions, and Input Boxes 108</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">11 Structured Programming: Decisions 113</p> <p style="MARGIN: 0px">11.1 Structured Programming 114</p> <p style="MARGIN: 0px">11.2 Flowcharts 115</p> <p style="MARGIN: 0px">11.3 The If/Then/Else Decision Structure 116</p> <p style="MARGIN: 0px">11.3.1 Indentation 117</p> <p style="MARGIN: 0px">11.3.2 Single Decision Structure (If/Then) 118</p> <p style="MARGIN: 0px">11.3.3 Single-Line If Statement 119</p> <p style="MARGIN: 0px">11.4 If/Then/Elseif Structure 120</p> <p style="MARGIN: 0px">11.5 Select Case Structure 121</p> <p style="MARGIN: 0px">11.5.1 If/Then/ElseIf Versus Select Case 122</p> <p style="MARGIN: 0px">11.6 Nesting 123</p> <p style="MARGIN: 0px">11.7 Compound Logical Expressions 125</p> <p style="MARGIN: 0px">11.7.1 Logical Complements and DeMorgan’s Theorem 128</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">12 Structured Programming: Loops 133</p> <p style="MARGIN: 0px">12.1 Decision Loops (Do/if Exit) 134</p> <p style="MARGIN: 0px">12.2 Count-controlled Loops 135</p> <p style="MARGIN: 0px">12.3 Nesting of Loops and Decisions 138</p> <p style="MARGIN: 0px">12.4 Recursion 139</p> <p style="MARGIN: 0px">12.4.1 Hands-on Exercise: Nonrecursive and Recursive Factorial Functions 140</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">13 Data Structures: Arrays and Records 147</p> <p style="MARGIN: 0px">13.1 Arrays 148</p> <p style="MARGIN: 0px">13.1.1 Hands-on Exercise: Loops and Arrays 150</p> <p style="MARGIN: 0px">13.1.2 Multidimensional Arrays 152</p> <p style="MARGIN: 0px">13.1.3 Changing an Array’s Lower Bound 153</p> <p style="MARGIN: 0px">13.1.4 Passing Arrays to Procedures 153</p> <p style="MARGIN: 0px">13.1.5 Hands-on Exercise: The Bubble Sort 155</p> <p style="MARGIN: 0px">13.1.6 Dynamic Arrays and the ReDim Statement 157</p> <p style="MARGIN: 0px">13.2 Records 158</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">14 Creating and Accessing Files 164</p> <p style="MARGIN: 0px">14.1 Sequential Files 165</p> <p style="MARGIN: 0px">14.1.1 Hands-on Exercise: File Manipulations 167</p> <p style="MARGIN: 0px">14.2 Other File Operations 170</p> <p style="MARGIN: 0px">14.2.1 GetOpenFilename Method 170</p> <p style="MARGIN: 0px">14.2.2 GetSaveAsFilename Method 172</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">15 Custom Dialogue Boxes 175</p> <p style="MARGIN: 0px">15.1 A Simple Custom Dialogue Box 176</p> <p style="MARGIN: 0px">15.1.1 Hands-on Exercise: Developing a Simple Custom Dialogue Box 176</p> <p style="MARGIN: 0px">15.2 Custom Dialogue Boxes and Modules 183</p> <p style="MARGIN: 0px">15.2.1 Hands-on Exercise: Custom Dialogue Box and Modules 183</p> <p style="MARGIN: 0px"> </p> <p style="MARGIN: 0px">References 188</p> <p style="MARGIN: 0px">Index 189</p> <p style="MARGIN: 0px"> </p>