View Single Post
  #2 (permalink)  
Old September 19th, 2006, 10:32 AM
woodyz woodyz is offline
Friend of Wrox
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts

Worksheet is also a class with properties and methods (subs and functions) on it, such as the Name property and the Calculate method.

In your code:

Book is an object of the Workbooks class
The line: "Set Wsheet = Book.Add.Worksheets(1)" creates a workbook using the Workbooks.Add method which returns a workbook object (which has a Worksheets object with 3 default worksheets in it at this time). However, rather than assigning this object to a reference variable, your code uses the created Worksheets property of the Workbook object to return the first Worksheet in the Worksheets collection.

Book - Is a Workbooks object

Book.Add - Is a method on the Workbooks object which adds a workbook to the Workbooks collection

Book.Add.Worksheets - Is an object refering to the Worksheets collection object of the Workbook just added to the Workbooks

Book.Add.Worksheets(1) is using the default Item method of the Worksheets collection to access a Worksheet object. In this case, the first of 3 default worksheets. In other words, your code could also have been written like this:
Set Wsheet = Book.Add.Worksheets.Item(1)

Woody Z