Saturday, January 31, 2009

VBA Macro Excel Tutorial: Objects and Collections

Objects
An object is a special type of variable that contains both data and codes. Some object can contains other object. For example, the Application object (or, Excel itself) contain others object, that is Workbooks. And a Workbook contain other object, such as Worksheets.

Collections
A collection is group of object of the same class. Workbooks is a collection of all Workbook object and Worksheets is a collection of all Worksheet object. To reference a single object from collections, you can put the object's name or the index number, like this:

Workbooks("Book1") or Workbooks(1) if Book1 is the first workbook in the collection.

No comments:

Post a Comment