The With Statement

In fact, VBA provides a With statement to handle just the situation in the previous example, which could be written as follows:

Dim fnt As Font

Set fnt = ActiveSheet.Rows(1).Font With fnt

.Bold = True .Italic = True .Underline = False .Size = 12 .Name = "Arial" End With

The general syntax of the With statement is:

With object

' statements go here End With where the statements generally refer to the object, but do not require qualification using the object's name, as in the previous example.

0 0

Post a comment