O'Reilly logo

Excel 2003 VBA Programmer's Reference by Robert Rosenberg, Rob Bovey, John Green, Stephen Bullen, Paul T. Kimmel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3

The Application Object

In this chapter we will examine 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 3-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 the 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required