Microsoft Office Tutorials and References
In Depth Information
Chapter 3
Exploring Visual Basic
for Applications
An Overview of Object-Oriented
Working with Macros . . . . . . . . . . . . . . . . 29
Programming . . . . . . . . . . . . . . . . . . . . . .25
This chapter provides an overview of how macros work in the context of Microsoft Office
Excel 2003. The second part of the chapter covers macro recording and other related topics,
but the first part steps back and gives you some perspective on what is happening when you
create a macro. The quick version of that story is that Visual Basic for Applications (VBA)
sees Excel as a series of objects that have attributes to describe them and actions those objects
“know” how to take. Chapter 1, “What’s New in Microsoft Office Excel 2003,” showed you
some of the basic elements you’ll encounter when using and programming Excel; this
chapter takes that analysis a few steps further by showing you how object-oriented program€
ming languages represent those elements, and how to manipulate those objects using the
macro recorder.
An Overview of Object-Oriented Programming
A computer program is, at its base, nothing more than a set of instructions the computer
executes in a specified order. In Excel, that order may change based on the contents of the
worksheet the program is working with, but one fundamental principle behind program€
ming languages is that if you give a program an identical data set to work with you will get the
same result every time.
The first generation of popular programming languages were procedural languages, which
meant that programmers designed an algorithm, or procedure, for the program to follow
and defined variables (placeholders for values) as the program developed. As programs
became increasingly complex, the need for descriptive variable names increased in impor€
tance. While it’s easy to create a variable named price to store the price of a product you offer
for sale in a store, it’s difficult to write an expandable program that can keep track of all of the
prices in an ever-changing product inventory. Every time you wanted to add a product to
your store, you would need to create a new variable. Doing that once or twice is no big deal,
but if you write a lot of programs and want to save time and effort by reusing your code, you
need some way of organizing your program around the things in your environment.
Search JabSto ::

Custom Search