The Global Object

As mentioned earlier in this chapter, Excel provides shortcuts into its object hierarchy through properties like ActiveCell and the Sheets collection. Those shortcuts are actually members of the Global object, which is a sort of default object that Excel uses if you omit an object name. This allows you to write code like:

    ActiveCell = 42

rather than:

    Application.ActiveCell = 42

The Global object includes many of the same members as the Application object, as shown in this list:

ActiveCell

ActiveChart

ActiveDialog

ActiveMenuBar

ActivePrinter

ActiveSheet

ActiveWindow

ActiveWorkbook

AddIns

Application

Assistant

Calculate

Cells

Charts

Columns

CommandBars

Creator

DDEAppReturnCode

DDEExecute

DDEInitiate

DDEPoke

DDERequest

DDETerminate

DialogSheets

Equals

Evaluate

Excel4IntlMacroSheets

Excel4MacroSheets

ExecuteExcel4Macro

Intersect

MenuBars

Modules

Names

Parent

Range

Rows

Run

Selection

SendKeys

Sheets

ShortcutMenus

ThisWorkbook

Toolbars

Union

Windows

Workbooks

WorksheetFunction

Worksheets

Many of these members return objects or collections, so they look like absolute references. In reality, they are all members of the Global object (even Application is a property of the Global object). In short, the Global object is the granddaddy of all the Excel objects.

You don’t have to understand the Global object to use Excel’s object library, but knowing something about it helps explain why the same objects turn up at various levels in the Excel object hierarchy. It also helps to explain how the Excel team implemented their objects, which is useful for advanced tasks, such as using the Excel object library from other programming languages, like Visual Basic .NET and C#.

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.