Читать книгу Excel 2019 Power Programming with VBA - Michael Alexander, Dick Kusleika - Страница 108

Understanding properties

Оглавление

Properties are essentially the characteristics of an object. Your house has a color, a square footage, an age, and so on. Some properties can be changed, like the color of your house. Other properties can't be changed, like the year your house was constructed.

Likewise, an object in Excel, like the Worksheet object, has a sheet name property that can be changed, and a Rows.Count row property that cannot.

You refer to the property of an object by referring to the object and then the property. For instance, you can change the name of your worksheet by changing its Name property.

In this example, you are renaming Sheet1 to MySheet:

Sheets("Sheet1").Name = "MySheet"

Some properties are read-only, which means you can't assign a value to them directly—for instance, the Text property of a cell. The Text property gives you the formatted appearance of value in a cell, but you cannot overwrite or change it.

Some properties have arguments that further specify the property value. For instance, this line of code uses the RowAbsolute and ColumnAbsolute arguments to return the address of cell A1 as an absolute reference ($A$ 1).

MsgBox Range("A1").Address(RowAbsolute:=True, ColumnAbsolute:=True)

Excel 2019 Power Programming with VBA

Подняться наверх