Wednesday, July 7, 2010

Properties

Properties
Properties are used to describe an object. Some properties are read-only, while others are read/write. These properties describe Excel objects. For example, an Excel workbook has a particular path on your hard drive or network where it is saved. That path is a property of the workbook. That path is read-only as it cannot be changed without saving the file to a different location. Properties are separated from objects by periods just as methods are. The following sentence will display the current path of the Loan Calculator.xls file in an onscreen message box:

Msgbox Workbooks(“Loan Calculator.xls”).Path

Note: Msgbox is a function. Functions will be discussed later in this section.

If you want to set a read/write property equal to something, it changes the current value of that particular object. If you don’t set a read/write property equal to something, Excel will tell you the object’s current value. For example, the following sentence will set the sheet name of the first sheet in the workbook to “Cover”

Sheets(“Sheet1”).Name = “Cover”

No comments: