Microsoft Office Tutorials and References
In Depth Information
Lesson 5: Object-oriented
Programming — an overview
In Lesson 1, you saw a brief historical synopsis of VBA. One particular facet of VBA’s
evolution that is worth more explanation is object-oriented programming, or OOP.
Object-oriented programming came about in the 1980s as a new concept in computer
programming. Its popularity grew over time, and with good reason — OOP’s original
precepts are at the core of today’s VBA programming language for Excel.
WHAT “oBjEcT-oriEnTEd progrAMMing” MEAns
Visual Basic for Applications is an object-oriented programming language. The basic concept
of object-oriented programming is that a software application (Excel in this case) consists of
various individual objects, each of which has its own set of features and uses. An Excel
application contains cells, worksheets, charts, pivot tables, drawing shapes — the list of Excel’s
objects is seemingly endless. Each object has its own set of features, which are called
properties , and its own set of uses, called methods .
You can think of this concept just as you would the objects you encounter every day, such as
your computer, your car, or the refrigerator in your kitchen. Each of those objects has
identifying qualities, such as height, weight, and color. They each have their own distinct uses, such
as your computer for working with Excel, your car to transport you over long distances, and
your refrigerator to keep your perishable foods cold.
VBA objects also have their identifiable properties and methods of use. A worksheet cell is an
object, and among its describable features (its properties) are its address, its height, its
formatted color, and so on. A workbook is also a VBA object, and among its usable features (its
methods) are its abilities to be opened, closed, and have a chart or pivot table added to it.