![]() One of the commonly used property is is Range(“A1:A10”).cells which refers to all the cells in the range. Range has a lot of useful methods and properties. For example Range(“A1:A10”) refers to the cells A1:A10 in the current worksheet. Range object is used to refer to a range of cells. In this section, we will examine these objects. While there are no single set of objects that are used by everyone for every need, there are a few VBA objects that are used in many situations. Since many Excel objects have dozens of properties and methods associated with them, to help us understand and use right properties, VBE (Visual Basic Editor) shows all the properties and methods whenever you press. Notice how the dot (.) is used like of in our plain English version.ĭot (.) is your best friend when dealing with objects. ![]() In Excel VBA language, the same becomes Range(“A4”).Interior.Color In plain English, if you want to know the color of a cell, you would ask “What is the color of cell A4?” How do we access these properties & methods? For example, select a cell, Excel internally runs SelectionChange Event on the current worksheet. An Event is a special type of method that runs only when a circumstance is met. Note: Certain objects also have a special class of methods called as Events. Methods are operations you do on the object. ![]() In other words, properties are what an object has. You use copy method to copy cell’s value to Excel’s clipboard. In VBA world, objects are made of 2 things – properties & methods. In the case above, color RED is a property of the cell object. Here is an illustration to help you understand the difference.Īs you can guess, Objects have Properties. Well, to know that, you must understand how an Object looks to our eyes vis-a-vis computer’s eyes. Since your Excel workbook is nothing but a collection of objects, whenever you want to make any change (like modify a cell’s value or recolor a chart), you need to refer to the corresponding object and do the necessary thing.īut how do we talk to these objects from VBA. Some sample objects you can find in Excel workbooks But that is a whole different subject.įrom our “We are nuts” example yesterday, you can already see these objects: For that matter, Lady Gaga’s meat dress is an object too. Your dog, your bed, your neighbors cat, their car, your bike, your computer, the shiny new Excel workbook you just created, my website, your email account – every thing is an object. Objects – what are they?Īny thing and everything is an object. In part 3 of our VBA Crash Course, we are going to learn how to speak with various Excel objects like Cells, Ranges etc.
0 Comments
Leave a Reply. |