View Single Post
  #3 (permalink)  
Old September 19th, 2006, 11:39 PM
dpkbahuguna dpkbahuguna is offline
Friend of Wrox
 
Join Date: Jan 2006
Location: Hardwar, Uttranchal, India.
Posts: 180
Thanks: 1
Thanked 1 Time in 1 Post
Send a message via ICQ to dpkbahuguna Send a message via MSN to dpkbahuguna Send a message via Yahoo to dpkbahuguna
Default

Quote:
quote:Originally posted by woodyz
 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.

So...
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 http://www.learntoprogramnow.com
--------------------------------------------------
Thanks woodyz !

As u said that

The line: "Set Wsheet = Book.Add.Worksheets(1)" creates a workbook using the Workbooks.Add method



so if Add is a method then how can we use the .(DOT) operator after the function name and one thing more that there is no parenthesis here too.

And as you said that

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


As I am getting in this line you want to say that worksheets is the class..
So if it is class then how a class can pass the parameter..
as it is passing like worksheets(1)

I am really so confused..
So pls woodyz help me here
Waiting for your reply…


DPK..