Chapter 2. The Application Object

This chapter examines a range of Excel functionality, looking at features that are not necessarily related to each other. In general, the Excel object model contains objects designed to address quite specific tasks. The Application object sits at the top of the Excel object model hierarchy and contains all the other objects in Excel. It also acts as a catch-all area for properties and methods that do not fall neatly into any other object, but are necessary for programmatic control of Excel. There are Application properties that control screen updating and toggle alert messages, for example. There is an Application method that calculates the formulas in the open workbooks.

Globals

Many of the Application object's methods and properties are also members of <globals>, which can be found at the top of the list of classes in the Object Browser, as shown in Figure 2-1.

If a property or method is in <globals>, you can refer to that property or method without a preceding reference to an object. For example, the following two references are equivalent:

Application.ActiveCell
ActiveCell

However, you do need to be careful. It is easy to assume that frequently used Application object properties, such as ScreenUpdating, are <globals> when they are not. The following code is correct:

Application.ScreenUpdating = False

You will get unexpected results with the following:

ScreenUpdating = False

This code sets up a new variable and assigns the value False to it. You can easily ...

Get Excel® 2007 VBA Programmer's Reference 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.