With statement
Execute a series of statements on an object.
With object
statements
End With
Parameters
Object
Required. It can be an object name or a function whose return value is an object.
Statements
Required. To pairObjectOne or more commands.
Description
WithA statement can be used to execute a series of statements on a specified object, but the object name does not need to be repeated. For example, if you want to modify multiple attributes of an object, you can place all attribute assignment statements inWithIn the control structure, the object can be referenced only once instead of in every value assignment statement. The following example shows how to useWithStatement to assign values to the attributes of the same object.
With MyLabel .Height = 2000 .Width = 2000 .Caption = "
This isMyLabel"
End With
Although the attribute operation is to useWithThe maximum number of statements. Its usage is not limited to this.WithBlock.
Note:Once you enterWithBlock,ObjectIt cannot be changed. Therefore, you cannot useWithStatement to change the values of several objects.
Can be nestedWithStatementWithThe block is written in another block. However, due to externalWithThe member of the block isWithBlock masking, regardless of the internalWithBlock to reference externalWithAny member of an object in the block must be referenced by a fully qualified object.
Key PointsDo not jump in or outWithBlock. IfWithThe statement in the block is not executed.WithOrEndStatement.