The most obvious difference between objects and other parts of the Visual Basic language is the dot notation. Objects use the period (or dot) to separate the object name from the member name as shown in Figure 4-1.
Member is the general term for a property, method, enumeration, or constant that belongs to the object. Objects help organize members
by grouping them into functional units. Objects are used throughout Visual Basic to organize things. In fact, if you type VBA.
in the Code window, you’ll see a list of the functions that are part of the Visual Basic language (Figure 4-2).
The VBA object
library even uses dot syntax to organize other objects. For example, type VBA.Strings.
and you’ll see a list of the string functions. The symbols in the Auto Complete list identify the type of member, as shown in Figure 4-3.
Figure 4-3. Objects can use other objects to organize members, and the type of member is illustrated by an icon
In Figure 4-3, the Library symbol identifies a grouping of related members ; the Enumeration symbol identifies a grouping of related constants. Visual Basic uses these same icons in the Object Browser —a tool that lets you explore the objects contained in any of the object libraries (Figure 4-4). To see the Object Browser, press F2.
The Object Browser lists only the object libraries that you have established references to. That means the libraries listed in the Object Brower’s drop-down list match the checkboxes selected in the Visual Basic References dialog box (Figure 4-5).
You may notice that not all of the Visual Basic language is listed in the VBA object library. Keywords like If
, Sub
, Function
, and End
are structural components and so aren’t part of the library. I covered those keywords
(sometimes called reserved words
) in Chapter 2, and I covered the members of the VBA object library in Chapter 3.
You need to know about two other icons in the Object Browser (see Figure 4-6):
- Global members
Members for which you can omit the object name. In the case of the VBA object library, all members are global so you never have to type
VBA.
. In the case of the Excel object library, the global members are often synonymous with theApplication
object. That means thatApplication.ActiveSheet
andActiveSheet
are equivalent expressions.- Events
Procedures that execute automatically when something happens in Excel. They take the form
objectname
_
eventname
in Visual Basic.
Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.