VBA objects and properties in Excel
An Object, in simple terms, is a physical entity that has existence.
In Programming also, an Object is an entity and its characters and specifications are defined by properties and methods.
Most of the programming languages are object oriented and VBA is no exception, except that, it is not fully object oriented.
This means, VBA does not have all the specifications as defined in the OOPS theory, but it does deals with objects.
For example, Excel worksheet, workbook,Range, Cells, all are treated as objects.
The Left side panel of the VBA editor shows the list of objects as shown below
So What are Properties?
Properties are nothing but the characteristics of the objects that are measurable and can be quantified.
For example, a Sheet is an object but its Name is a property.Yes, it has a property named "Name".
Similarly, a Range object has Font property, Colorindex, Value property and so on.
The following example illustrates these concepts. For this we created the Sheet Q25.
- Sub objects_example()
- Sheets("Q25").Range("F26").Value = "Test"
- Sheets("Q25").Range("F26").Interior.ColorIndex = 5
- MsgBox "Properties demo; See F26"
- End Sub
The Screenshot of the editor is as shown below