Item Property

The Item property returns a particular workbook in the Workbooks collection. For instance:

Workbooks.Item(l)

returns the Workbook object associated with the first workbook in the Workbooks collection. Since the Item property is the default property, we can also write this as:

Workbooks(l)

Note that we cannot rely on the fact that a certain workbook will have a certain index. (This applies to all collections.) Thus, to refer to a particular workbook, you should always use its name, as in:

Workbooks("Book1.xls")

It is important to note that if a user creates a new workbook named, say, Book2, using the New menu item on the File menu, then we may refer to this workbook in code by writing:

Workbooks("Book2") but the code:

Workbooks("Book2.xls")

will generate an error (subscript out of range) until the workbook is actually saved to disk.

0 0

Post a comment