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?
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?