Returning an Object from a Collection

   

The Item property returns a single object from a collection. The following statements set the fileOne variable to a WebFile object that represents the first file in the Files collection.

Dim fileOne As WebFile

Set fileOne = ActiveWeb.RootFolder.Files.Item(0)

The Item property is the default property for most collections, so you can omit the Item keyword as shown in the following statement.

Set fileOne = ActiveWeb.RootFolder.Files(0)

Named Objects

Although you can usually specify an integer value with the Item property, it may be more convenient to return an object by name. The following example edits a file named Web Sales.htm in the active web.

ActiveWeb.RootFolder.Files("Web Sales.htm").Edit