A property refers to what an object has.
As an analogy, a car has a predefined set of properties such as color, size, type, engine, etc.
Likewise, an Excel object could have its own set of properties, such as color, font, and value.
Properties come after the object hierarchy.
This means that the object is specified first, followed by a period, then the property name, and the details or value assigned to it.
It also has to be specific in cases where there might be some ambiguity.
Taking a car and a shoe as examples:
Car.Color – might be too broad
Car.Interior.Color = Black – this makes sure that Excel knows which part of the car is being referred to.
There are different property scenarios in Excel
- Some properties don’t have details
- Some properties return an object – this occurs when an object’s property is also an object with its own properties
- Range(“A2”).Interior.Color – The Range A2 has Interior as its property, while Interior has Color as its property.
An interior property returns an interior object.
More details on this can be found through Microsoft Help.
A property can be either read-only, write, or both.
Below are some use cases:
- Range(“A1”).Value = ActiveCell.Address
- This reads the address of the active cell and puts it as the value of cell A1.
- Range(“A1”).Interior.Color = vbRed
- This assigns the color red to cell A1’s interior.
- Range(“A1”).Font.Color = vbBlue
- This changes the font color of cell A1 to blue.