With statement help

arage

Registered User.
Local time
Today, 14:04
Joined
Dec 30, 2000
Messages
537
The following is from access97 help:

In Visual Basic, usually you must specify an object before you can run one of its methods or change one of its properties. You can use the With statement to specify an object once for an entire series of statements.

You can nest With statements for greater efficiency. The following example inserts a formula into cell A1, and then formats the font.

Sub MyInput()
With Workbooks("Book1").Worksheets("Sheet1").Cells(1, 1)
.Formula = "=SQRT(50)"
With .Font
.Name = "Arial"
.Bold = True
.Size = 8
End With
End With
End Sub

I would like to know why in the MyInput() example the WITH occurs twice if the object in question is the object Workbooks("Book1").Worksheets("Sheet1"), imho I was only expecting the initial WITH to be enough to specify the object, what is the second WITH accomplishing?
 
Hi arage,

this should probably be in the excel section but the answer is that the first with applies to the cell and the second to the font of the cell ( which is a property of the cell and behaves as its own object ). The details of the font are then set before the font with is exited and then the cell with is exited. hope that makes sense

idea.gif


KDG

- sorry about the smiley, just wanted to post it somewhere!
 
thanks KDG, no prob on the smiley, but the example DID come from access97 help, they should have put something related to access in there instead, but oh well
 

Users who are viewing this thread

Back
Top Bottom