Microsoft Office Tutorials and References
In Depth Information
Some Useful Application Properties
The advantage of using these properties to return an object is that you don’t need to know which
cell, worksheet, or workbook is active, and you don’t need to provide a specific reference to it.
This allows you to write VBA code that isn’t specific to a particular workbook, sheet, or range. For
example, the following instruction clears the contents of the active cell, even though the address
of the active cell isn’t known:
The example that follows displays a message that tells you the name of the active sheet:
MsgBox ActiveSheet.Name
If you want to know the name and directory path of the active workbook, use a statement like this:
MsgBox ActiveWorkbook.FullName
If a range on a worksheet is selected, you can fill the entire range with a value by executing a
single statement. In the following example, the Selection property of the Application object
returns a Range object that corresponds to the selected cells. The instruction simply modifies the
Value property of this Range object, and the result is a range filled with a single value:
Selection.Value = 12
Note that if something other than a range is selected (such as a ChartObject or a Shape ), the
preceding statement generates an error because ChartObject and Shape objects don’t have a
Value property.
The following statement, however, enters a value of 12 into the Range object that was selected
before a nonRange object was selected. If you look up the RangeSelection property in the
Help system, you find that this property applies only to a Window object.
ActiveWindow.RangeSelection.Value = 12
To find out how many cells are selected in the active window, access the Count property. Here’s
an example:
MsgBox ActiveWindow.RangeSelection.Count
Search JabSto ::

Custom Search