The Excel Object Model

As mentioned in the previous post, Excel has a whole bunch of objects that can be manipulated to do whatever you need. The collection of all objects and how they relate to each other is referred to as the Excel Object Model. The actual object model diagram supplied within Excel’s help file is fairly complex and probably won’t make a great deal of sense at this stage. There is a hierarchical relationship between many of the objects in Excel:

  • The Application object contains Workbook objects.
  • Workbook objects contain Worksheet objects.
  • Worksheet objects contain Range objects.

Each of these objects have their own properties, methods and events. Some objects can have properties that are also objects. Rewind that: objects can have properties that are also objects. For example, a range object has a property called Font. The Font property is an object which in turn has its own properties (but no methods or events). Maybe a short example will help illustrate the point:

You are hopefully now comfortable with a statement such as this:

Range(“A1″).Value = 10

This will assign the value 10 the a range object representing cell A1.

Say for example you want to change the font size of cell A1. You would use a statement like this:

Range(“A1″).Font.Size = 8

This statement flows from left to right with the top-most object first (the range object) followed by the second object (the font object). We then assign the value 8 to the Size property. A line of code can have as many objects in as necessary to complete a given task e.g.

Application.ActiveWorkbook.ActiveSheet.Range(“A1″).Font.Size = 8

This line actually achieves the same effect as Range(“A1″).Font.Size = 8. This is because if you omit the Application.ActiveWorkbook.ActiveSheet part of the code, Excel assumes you want to work with the active sheet of the active workbook, within the Excel application.

This tutorial has covered some important but possibly confusing concepts. VBA is an object orientated programming (OOP) language. The (Excel) environment consists of many different objects that represent various aspects of the application. Objects have properties, methods and they expose events (events will be covered in the next tutorial).

VBA uses the ‘dot syntax’. When you want to change an object’s property of execute a method of an object you type the object name followed by a dot (i.e. a full stop) and then the name of the property or method you want to work with. When you type the dot VBA will usually display a drop-down list of properties and methods for that object.

This one also comes from: http://www.danielklann.com/tutorials/2/introducing_vba_language.htm

Incoming search terms:

  • excel object model
  • excel object model diagram
  • range object method and properties
  • Draw basic Excel Object Model
  • programming the excel object model
  • how to get javascript excel object length
  • excel vba objects hierarchy
  • Excel VBA object model diagram
  • excel type web objects
  • excel object model mit web applikation
This entry was posted in Programming and tagged . Bookmark the permalink.

One Response to The Excel Object Model

  1. billig says:

    Magnificent issues altogether, you just won a emblem new reader. What may you suggest about your put up that you made some days in the past? Any sure?