Newbie Questions
Hi guys,
I am totally new to vba programming and wanted to know if anyone could explain the relationship between classes, objects, methods, and properties. I bought a good book on vba for excel, but am still a little confused. Can anyone clarify? |
Newbie Questions
An object is an entity such as a workbook, worksheet or range (Like a
noun). In the object browser, objects will usually be refered to as a class. an object can have properties (attributes) (properties can themselves be objects) Workbook Name Worksheets Worksheet Name UsedRange parent <== also an object (workbook) Range <== also an object Range address Interior.colorIndex Font.colorIndex visually, a range has a background color and a font color. However, in the object model, the range has an interior (object) which can have a color or colorindex and the font can have a name, size, color, colorindex. The reason these are objects is because other types of objects can also have interiors and fonts. So this makes them reusable. If the property is not read only, you can assign it a value Activeworkbook.Worksheets("Sheet1"). Range("A1").Interior.ColorIndex = 3 ' Makes the cell A1 red. A method is like a verb, it performs an action ActiveWorkbook.Worksheets.Add adds a new worksheet the active workbook A class is generally used to refer to a developer defined object that will usually also have properties and methods created by the developer using a class module. However, as was stated at the start, a more general view is that class and object are interchangable. I am sure others will have useful thoughts as well. Note that none of the listings used are exhaustive, but are illustrative. -- Regards, Tom Ogilvy "Steve P" <Steve wrote in message ... Hi guys, I am totally new to vba programming and wanted to know if anyone could explain the relationship between classes, objects, methods, and properties. I bought a good book on vba for excel, but am still a little confused. Can anyone clarify? |
Newbie Questions
'Class' and 'object' are sometimes used interchangeably. A way to keep
them distinct is to use 'object' to mean an instance of a class. E.g. Worksheet is a class, and Sheet1 is an object. A property is a property of an object, e.g. Cells is a property of Sheet1, Value is a property of each Cell. A method is a procedure for adding, changing, or deleting properties to an object, or adding or deleting an instance object of a class. Each class has a prescribed set of properties and methods that are used to define or alter an object in that class. Hth, Merjet |
Newbie Questions
Thank you for that Tom.
Do you ever sleep? -- Robert |
Newbie Questions
Snow Day <g
-- Regards, Tom Ogilvy "Robert" wrote in message ... Thank you for that Tom. Do you ever sleep? -- Robert |
All times are GMT +1. The time now is 08:12 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com