The Application Object

The Application object is the top-level object in Excel's object model. It represents the entirety of the Excel application (see Figure 5.6). As the top-level object it is unique and thus, seldom needs to be addressed in code; however, there are a few occasions when you must use the Application object's qualifier in code. One example is the OnTime() method used in the Math Game program in Chapter 4. Other examples where the Application object must be explicitly referenced in code include the Width and Height properties used to set the size of the application window, and the DisplayFormulaBar property used to show or hide the formula bar.

Application.Width = 600 Application.Height = 450 Application.DisplayFormulaBar = True

For the most part, you need to use the Application object qualifier to set properties pertaining to the appearance of the Excel window, such as shown above, or the overall behavior of Excel as shown below.

Application.Calculation = xlManual Application.EditDirectlylnCell = False Application.DefaultFilePath = "C:\My Documents"

The Application object qualifier must also be used with the very helpful ScreenUpdating and WorksheetFunction properties.

Application.ScreenUpdating = False

Range("A11") = Application.WorksheetFunction.Sum(Range("A1:A10"))

However if you just need to set properties of lower-level objects, then the Application object qualifier is not needed.

ActiveCell.Formula = "=SUM(A1:A10)"

The line of code above uses the ActiveCell property of the Application object to return a Range object. The Range object returned by this line of code is the currently selected spreadsheet cell. The Formula property of the Range object is then set with the given string. The formula is then entered into the cell and the result calculated as normal by Excel. To view all the Application object's properties, methods, and events, select it from the Classes list in the Object Browser, as shown in Figure 5.10.

The Application object as viewed through the Object Browser.

- Ill Llht-il tee ■ -rj < I ► I I

Cesses

Members or^plicaGon'

AtlowEditRanges

Adii/ateMicrasoltftpp

¿5J AnsweiWlzard

AciiweCell

ËS A^sweiYVizardFilae

g? AeliveChart

S3 Application !

eS1 AcllvePrinter

Areas

sS" AcliweSheet

¿i Assistant

& AcliveWindow

ÖS AuloCorreet

m AcllvaWorkttook

as AUlOFilter

Ad üC hartftutoF ormat

AuloRecover

AddCustomLial

tffl Aas

g? Addlns

SS Atfs

AletlBeroteOveiwfiiine

¿5 MsTitîe

eS1 AJistartupPath

Balloon

Ö? AjiswerWizard

BaHoonCheckbox

Ap plicalion

Balloon Checkboxes

Artiitrar^LSupportAvaila&le

Si BaiioonLabei

tSf As ktq up date Links

I Class Ajjpicotlw

The Application object as viewed through the Object Browser.

The events associated with the Application obj'ect are not enabled by default so they will not work like other Excel object event procedures. Enabling events for the Application object involves the use of a class module and other advanced methods that are beyond the scope of this book and will not be discussed.

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Post a comment