Birds Eye View of the Application Object

The Application object has so many useful aspects that it is probably a good idea to quickly summarize. The vast majority of your Excel development tasks will involve performing actions or manipulating lower-level Excel objects, such as ranges and worksheets, along with standard variables that represent the basic data types. Normally you don't spend much time thinking about the Application object. When you do use it though, the functions it performs are often critical to your application. Other times the Application object provides functionality that serves to give your program a professional finish.

If you'll remember from Chapter 3, objects contain members that can be classified as methods or properties (events are also members, but I'll get to them later). You can group the members of the Application object with the following classifications.

Display-oriented members The Application object has a fairly large collection of members that deal in some way with the display. For example, such members control whether the screen gets updated, what appears in the status bar, the size of the window, and whether or not certain Excel objects are visible.

Excel convenience members As the root object of the Excel object model, the Application object provides access to any other object in the Excel object model. It also contains a lot of shortcuts that allow you quick access to many relevant Excel objects such as the ActiveCell, ThisWorkbook, and Selection.

File operations Occasionally you'll need to allow an end user to select a file to open or prompt the user for a place to save a file. The Application object contains members that assist with these activities.

System information If you need to determine information about the environment of the computer on which your application is running, you'll use the Application object. This group of members includes properties such as OperatingSystem, OrganizationName, and UserName.

Other members defy easy classification in one of these categories, so make a mental note that another group of miscellaneous members exists.

The Application object is somewhat unique. You don't need to declare a variable to represent an instance of it. In fact, you don't need to preface some of the Application object's members with the word Application in order to use them. For example, the following two lines perform the same function:

Debug.Print Application.ThisWorkbook.Name Debug.Print ThisWorkbook.Name

One thing that is strange is that for other members, you do need to fully qualify the member. The ScreenUpdating property is one such member.

' This line works

Application.ScreenUpdating = False ' This one doesn't ScreenUpdating = False

So, if in doubt, fully qualify the member using Application. I usually use the shortened version (without Application) when I'm using the members that begin with Active or This. You'll see examples of this throughout the chapter starting with Listing 5.1.

0 0

Post a comment