Working with Object Properties

Every object has a defining set of characteristics. These characteristics are called the object's properties, and they control the appearance and position of the object. For example, each Window object has a WindowState property you can use to display a window as maximized, minimized, or normal. Similarly, a Word Document object has a Name property to hold the filename, a Saved property that tells you whether or not the document has changed since the last save, a Type property to hold the document type (regular or template), and many more.

When you refer to a property, you use the following syntax: Object.Property

For example, the following expression refers to the ActiveWindow property of the Application object:


" You'll come across the word "active" quite often in your VBA travels,so let's make sure you know ® what it means. In the VBA world,active describes the item with which you're currently working. In Word, for example,the document you're currently using is the active document. Similarly, in Excel the worksheet cell that you're editing or formatting is the active cell. In programming lingo, the active item is said to have the focus.

One of the most confusing aspects of objects and properties is that some properties do double-duty as objects. Figure 5.1 uses an Excel example to illustrate this. The Application object has an ActiveWindow property that tells you the name of the active window. However, ActiveWindow is also a Window object. Similarly, the Window object has an ActiveCell property that specifies the active cell, but ActiveCell is also a Range object. Finally, a Range object has a Font property, but a font is also an object with its own properties (Italic, Name, Size, and so on).

0 0

Post a comment