'With Statement
'
'Executes a series of statements on a single object or a user-defined type.
'
'Syntax
'
'With Object
'[statements]
'
'End With
'
'The With statement syntax has these parts:
'
'Part Description
'object Required. Name of an object or a user-defined type.
'statements Optional. One or more statements to be executed on object.
'
'Remarks
'
'The With statement allows you to perform a series of statements on a specified object without requalifying the name of the object. For example, to change a number of different properties on a single object, place the property assignment statements within the With control structure, referring to the object once instead of referring to it with each property assignment. The following example illustrates use of the With statement to assign values to several properties of the same object.
Option Explicit
'Example With Statement
Sub TestWithStatement()
With Range("a1:f1")
.Interior.Color = vbRed
.Font.Color = vbBlue
.Font.Size = 18
.Select
.ColumnWidth = 20
End With
End Sub
'
'Executes a series of statements on a single object or a user-defined type.
'
'Syntax
'
'With Object
'[statements]
'
'End With
'
'The With statement syntax has these parts:
'
'Part Description
'object Required. Name of an object or a user-defined type.
'statements Optional. One or more statements to be executed on object.
'
'Remarks
'
'The With statement allows you to perform a series of statements on a specified object without requalifying the name of the object. For example, to change a number of different properties on a single object, place the property assignment statements within the With control structure, referring to the object once instead of referring to it with each property assignment. The following example illustrates use of the With statement to assign values to several properties of the same object.
Option Explicit
'Example With Statement
Sub TestWithStatement()
With Range("a1:f1")
.Interior.Color = vbRed
.Font.Color = vbBlue
.Font.Size = 18
.Select
.ColumnWidth = 20
End With
End Sub
No comments:
Post a Comment