Red An integer value between and that represents the red component of the color green An integer value between and that represents the green component of the color blue An integer value between and that represents the blue component of the color

To shorten this procedure, VBA provides the With statement. Here's the syntax:

With object

[statements] End With object The name of the object.

statements The statements you want to execute on object.

The idea is that you strip out the common object and place it on the With line. Then all the statements between With and End With need only reference a specific method or property of that object. In the FormatParagraph procedure, the common object in all six statements is ThisDocument.Paragraphs(1). Listing 5.2 shows the FormatParagraph2 procedure, which uses the With statement to strip out this common object and make the previous macro more efficient.

0 0

Post a comment