Understanding VBA Objects Properties and Methods in Excel is important, most of the programming languages today are Object Based Or Object Oriented Programming Languages. Although Excel VBA is not a truly object oriented programming language, it does deal with objects.
In this Section:
What are Objects?
Most of the programming languages today are Object Based Or Object Oriented Programming Languages. Although Excel VBA is not a truly object oriented programming language, it does deal with objects.
VBA object is something like a thing that has certain functions, properties, and can contain data or child objects.
In real world everything is an object. For example, House is an Object, Windows and Doors,etc… are child objects of the House. And House is having some characteristics or properties such as Color, Height, Number of Floors,etc.., and it also have some Events, such as Door Open, Door Close, etc….
Similarly, An Excel Worksheet is an object, and a Range or Cells in a worksheet are child objects of worksheet, Worksheet contains several Properties, Methods and Events.
You can go to the code window to view the VBA objects, the upper left drop-down list of the code window contains the list of objects and the right side drop-down list contains the associated objects.
What are Properties?
Properties are the characteristics of an Objects which can be measured and quantified, in the above example House is having properties like Width, Height, Color, etc…
Similarly, Excel Objects are having several properties which can be measured and quantified.
For example, a Range Objects is having Properties like Value,Font.ColorIndex, Interior.ColorIndex,etc…
Sub sbExampleRangeProperties() Range("A1").Value = 25 Range("A1").Interior.ColorIndex = 5 End Sub
What are Methods?
Methods are the actions that can be performed by an an Objects or on an Object. In the above Hose example, paintaing is a Method, building a new room is a method.
Similarly, if you want to select a range, you need Select method. If you want to copy a range from one worksheet to another worksheet you need Copy method to do it.
The following example Copies the data from Range A1 to B5.
Sub sbExampleRangeMethods() Range("A1").Select Selection.Copy Range("B5").Select ActiveSheet.Paste End Sub
VBA Objects Properties and Methods in Excel – Object Browser?
Object browser is a very helpful tool available in VBA, which helps you to veiw all available Objects in the Excel VBA. Click on the objects browser in the code window to view all the available Excel VBA objects and its associated Properties and Methods.