Page 8 - Microsoft Office Excel 2003 Programming Inside Out
P. 8
Table of Contents
Part 2
Visual Basic for Applications
Chapter 3
Exploring Visual Basic for Applications 25
An Overview of Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . 25
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Working with Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Recording and Viewing Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Running a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Debugging a Macro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Implementing Macro Security and Digital Signatures . . . . . . . . . . . . . 36
Chapter 4
VBA Programming Starter Kit 41
Introducing the Visual Basic Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Opening the Visual Basic Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Recognizing Parts of the Visual Basic Editor. . . . . . . . . . . . . . . . . . . 41
Customizing the Visual Basic Editor. . . . . . . . . . . . . . . . . . . . . . . . . 49
Managing Code Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Handling Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Adding Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Notes on Programming Style and Code Readability . . . . . . . . . . . . . . 54
Developing Projects with the Project Explorer . . . . . . . . . . . . . . . . . . . . . . 55
Creating VBA Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Deleting VBA Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Copying Modules Between Projects . . . . . . . . . . . . . . . . . . . . . . . . . 57
Declaring Variables, Constants, and Data Types . . . . . . . . . . . . . . . . . . . . 57
Declaring Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Defining Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Defining Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Handling Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Handling Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Handling Variants and Data Type Conversions. . . . . . . . . . . . . . . . . . 61
Understanding Variable Scope and Lifetimes . . . . . . . . . . . . . . . . . . 62
Assigning Values to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Working with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Creating an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Creating Multidimensional Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Creating Dynamic Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
viii