Generally, if a variable or other identifier can be resolved to a specific type, then Intellisense will show you the members of that type. For example:
Application.
will bring up a list of members.
Selection
is a special case because although the currently selected item is often a range of cells, it could be something else as well - part of a chart sheet for example.
You can discover the underlying type of the object which Selection
refers to, by adding a watch (Debug -> Add Watch...). Type Selection
in the Expression box, and set the context to (All Procedures) and (All Modules) if it's not set that way already.
In the Watches window, you will see the actual type of the object referred to by Selection
, and you can expand the +
to see its properties. If the type says Object/Range
, (meaning the type of the expression is Object
and the type of the object referred to by the expression is Range
), one of the properties will be Interior
. If you look at the type column for Interior
, you'll see Interior/Interior
, because the type of the Interior
property is indeed the Interior
type.
If you type the following in code:
ActiveCell.
Intellisense will show you a list of members, including the Interior
property, because the type of the ActiveCell
property is the Range
type.
Some other powerful tools for investigating the object model:
- The Object Browser (View -> Object Browser) shows you a list of types available to your project, based on the libraries which the project references (can be viewed/changed at Tools -> References...). When a type is selected, you will see a list of members for that type. You can filter the types by library and/or by name. Members in the
<globals>
type can be used without any object references -- Interior
needs some Range
object to be used, but Selection
can be used by itself.
- The Immediate window (View -> Immediate window) lets you evaluate expressions (preface with a
?
-- e.g. ?ActiveWorkbook.Sheets.Count
) and run code in place (such as ActiveWorkbook.Save
)