Objects, Methods, And Properties

Breaking up Excel into multiple objects gives the benefit of code reusability. It's possible to include a Chart object in a presentation, or a PivotTable object in an interactive document. The developer provides the code that sets up the object or helps the user make changes. The rest of the code is already debugged and documented. There are over six million lines of code in the Microsoft Office applications…that's a lot of code you don't have to write! To take advantage of these objects requires knowing some concepts that may be new to the reader.

Objects

Think of an object as something visible in the real world. For instance, a picture hanging on a wall is an object. In Excel, some objects are the Worksheet, Chart, and Range objects. In the real world, a person would change things about the picture by picking it up and doing whatever they want, within the limits of good taste. A developer changes things about Excel's objects through the VBA language.

Methods

Think of a method as an action done to an object. For instance: hanging the picture, cleaning the glass, or showing the picture if it had a velvet cloth covering it. In Excel, the Show method shows a dialog box; the Activate method makes a worksheet visible and ready for editing.

Properties

Think of a property as something that describes an object. A picture has a frame style, dimensions, and the photo itself. An Excel chart has similar properties; for instance the Border, Height, and Width properties of the ChartArea object. Code can both examine and change the values of a property if it can be written to, but some properties are read-only.

Collections

Collections are another useful concept. There could be a collection of all the pictures in a museum. In Excel, a collection is a group of similar objects. The Worksheets collection is all the Worksheet objects in a Workbook object. With collections, code can do things like list the names of all the worksheets in a workbook to build a table of contents. VBA has a For Each… statement that lets code step through all the objects in a collection, one at a time.