With statement
Executes a series of statements on an object.
With object
statements
End With
Parameters
Object
The required part. Can be either an object name or a function that returns a value to an object.
Statements
The required part. One or more commands that will be executed on object .
Description
The WITH statement can be used to execute a series of statements on the specified object, but it does not need to be repeated to describe the object's name. For example, if you want to modify multiple properties of an object, you can place all the property assignment statements in the with control structure so that the reference to the object is only needed once, not in every assignment statement. The following example shows how to use the WITH statement to assign values to several properties of the same object.
With MyLabel .Height = 2000 .Width = 2000 .Caption = "
This isMyLabel"
End With
Although a property operation is the most common case with a with statement, its usage is not limited to this. Any legitimate statements can be used in the With block.
Note that once you have entered the With block,object is immutable. Therefore, you cannot use A with statement to change the values of several objects.
The WITH statement can be nested, and a with block is written in another block. However, because the members of the outer with block are masked by the inner with block, whether the inner with block refers to any member of an object in an external with block, Must use a fully qualified object reference.
do not jump into or out of the With block. If you execute a statement in a with block without executing the with or end With statement, the result will cause an error or other unpredictable behavior.