Excel Object Model
Object Oriented Programming Property Method Event read write Each object in a Microsoft application has properties which you can view and/or change, methods which you can utilise within a procedure and associated events to which you can attach a sub-routine. Collection Object object
Object Oriented Programming read/write Property Method execute procedure A sub-routine can :- - exchange values with any of an object’s properties - instruct an object to carry out any of its methods - provide code to run when any of an object’s events occur Event triggers
Workbook Object Workbook (object) Worksheets (property) Workbook_Open (event) Close (method) You identify a collection of worksheets by using the enclosing workbook’s Worksheets property. Name (property) ActiveSheet (property) Collection Worksheet Worksheet Worksheet
Object Browser Window LIBRARY PROPERTIES METHODS EVENTS OBJECT CLASS Use the view menu to locate the Object Browser Window and ensure that you have the appropriate libraries selected before searching for the object of interest.
Sub Current_Workbook() Dim wb As Workbook Simple Sub-Routine Sub Current_Workbook() Dim wb As Workbook Set wb = Application.ActiveWorkbook Debug.Print wb.Name Set wb = Application.Workbooks(1) wb.Save End Sub OBJECT PROPERTY METHOD COLLECTION The sub-routine uses the variable wb to manipulate the active workbook.
References To Object Libraries Visual Basic For Applications Microsoft Excel Object Library OLE Automation Microsoft Office Object Library Another Workbook
Simple Object Hierarchy If in doubt about where the object you need lies in the hierarchy, start with the Application object and work down.
Create An Object Add Method new object collection
The object model is not perfectly consistent. Always Remember … The distinction between a property and a method is not always clear-cut. The object model is not perfectly consistent. The sub-routine uses the variable wb to manipulate the active workbook.