Navigating through the hierarchy

If you want to work with the Application object, it's easy: you start by typing Application. Every other object in Excel's object model is under the Application object. You get to these objects by moving down the hierarchy and connecting each object on your way with the dot (.) operator. To get to the Workbook object named "Bookl.xlsx", start with the Application object and navigate down to the Workbooks collection object.

Application.Workbooks("Book1.xlsx")

To navigate further to a specific worksheet, add a dot operator and access the Worksheets collection object.

Application.Workbooks("Book1.xlsx").Worksheets(1)

Not far enough yet? If you really want to get the value from cell A1 on the first Worksheet of the Workbook named Book1.xlsx, you need to navigate one more level to the Range object.

Application.Workbooks("Book1.xlsx").Worksheets(1).Range("A 1").Value

When you refer to a Range object in this way, it's called a fully qualified reference. You've told Excel exactly which range you wanted, on which worksheet and in which workbook, and have left nothing to the imagination. And that's a good thing. Imagination is good in people, but not so good in computer programs.

0 0

Post a comment