November 19th, 2010, 11:03 PM
Reading Object Hierarchy in a Object Model
Set oExcelApp = CreateObject("Excel.Application")
Set oWorkbook = oExcelApp.Workbooks.Open("G:\Documents and Settings\Arjun\My Documents\VBScripts\Practices\Excel Data\usernames.xlsx")
Set mySheet = oWorkbook.Sheets.Item("Sheet1")
As you see in the above code, I instantiated Excel Application Object and then Started using new object for opening an new spreadsheet, and new sheet.
oExcelApp is an Object reference as I created. Workbooks is a property of oExcelApp object and Open() is a method of oExcelApp.
Here is the part that I don't understand. How come a property will have a method, which is Open() in this case. Is workbook an Object? can object contain another object? Can Workbook be an object as well as property. I am totally confused.
My understanding based on what I read, if Excel Application is an object, then it has all the objects, new, open, close, save, edit, tools, options, just like what I see in GUI. And then each of these items will have methods and properties. I am not sure if I am thinking in right direction. but I need very good understanding of how these objects are organized and how I can refer them to use them in my programming.
Please help me if you know how to understand these objects.
Tags for this Thread
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!