The term application is generally applied to any software that requires one or more external modules to function. Applications are not self-contained software programs, but an application of code modules to achieve a spedfic goal. It has long been debated whether there is such a thing as a true program in the Windows environment or whether all Windews programs are actually applications. Project itself is often referred to as an application, but if it is an application, it is an executable application because, aside from Windows it doesn’t require external modules to run.
A Project application is simply a collection of custom toolbars, custom Project forms, and VBA modules-designed to work together to achieve a common objective. Applications created in Project 2000 are macro applications, as opposed to executable applications (programs) because Project applications require external modules from Project 2000. Project applications must be stored within a project document and run from within Project 2000. The only. real distinguishing feature between a simple macro (or any of the individual custom components that you have worked with so far)
and a macro application is pumbers. If you bring all the individual pieces together properly, their worth is greater than the sum of their individual parts
Managing Project Applications’
In Project 2000, you will work with two types of applications: template-based applications and global applications. Template-based applications contain customized functionality that applies only to a given template. Template-based applications often rely on views and custom fields that only exist within a template. The customized components for macros are placed in the template file
Global applications are far more generalized applications. These applications are designed to extend the functionally of Project 2000 itself. A properly constructed global application should be able to run (;)fl any Project document. Global applications cannot rely on specific items. (tasks, resources, or assignments) that exist within the project file. likewise, they are far more constrained in the use of custom fields.
All the customization that make up the application need to be served in the same place. If not, your project will not run correctly. After you have finished your application, use the Organizer to make sure that all the components of your project are stored together. The Organizer, discussed in Chapter 21, “Customizing Project 2000,” can also be used to distribute Visual Basic components between projects .
Public subroutines created in other standard modules can be used as macros, but the Macros dialog box always returns to the same module to create new macros, Even if you add standard modules to a project or rename the module, the Macro Recorder will still return to this module when you create new macros. By default, the first module created in the VBA project is named Modulel. Because this module is used to store macros, you should rename the module to reflect its special status. By convention, standard module names are prefixed with’ bas’ to denote the type of module; bas Macros would be a suitable name. To rename Module!, select Module! in the Project Explorer and change the module’s Name property in the Properties window:
Automating Other Applications from Project
VBA is not limited to Project. You can automate any application that supports automation(also referred to as OLE automation, ActiveX automation, or OLEInprocess serving) from within Project 2000. If you have been following along with the examples, you have already used ActiveX automation. VBA procedures, including macros, control Project through ActiveX automation. There is not much difference to automating other prog~ams In VBA;you simply need to have access to the objects of the application. There are two ways to access an object, just as there are two ways to declare VBvariables.
Late binding, also called weak typing, Is analogous to implidt declaration; early binding (strong typing) resembles expUdt declaration
Accessing an Object with Late Binding
The simplest way of accessing an object is through a process called late binding. In late binding, you use the Create Object or Get Object functions to retrieve an object. The following example opens the Excel workbook’ C:\My Documents\Employees. xl s ‘. It then reads rows 2 through 11 of the Excel spreadsheet and creates a Project resource for each line, setting the standard rate and the overtime rates for the default pay rate table. Of course you could do the same thing using an import map (see “Importing and Exporting Project Data”), but in a few pages, we’ll create a similar procedure to link rather than import Excel data from Project 2000
Dim pjResource As Resource
Dim xlSheet As Object
Dim i As Integer
Set xl Sheet – GetObject(‘C:\My Documents\Employees.xls’)
For i – 2 To 11
Set pjResource – Resources.Add(xlSheet.Cells(i, .l).Value)
pjResource.StandardRate – xlSheet.Cells(i, 2).Value
pjResource.OvertimeRate – xlSheet.Cells(i, 3).Value
Accessing an Object with Early Binding
Alternately, you can use early binding, which is analogous to explicit variable declaration. With early binding, you declare the type of application that an object comes .from before using it:
Dim xlApp <‘3″ Exce1.Application
Then, you can refer to specific objects within the Excel Application object in your procedure. Early binding has two major advantages:
• Applications run more quickly and efficiently because part of the work is handled at compile time .
• You can use the Object browser and the Auto List Members feature of VBA to create the code
Early binding also has one huge disadvantage. If the object library that includes the object isn’t installed on the machine, your application won’t run, even if the application does not need the object at the time. To use early binding, you need to add a reference to the object library for the program you wish to automate. Whether or not you use early binding, the error-checking and Auto List help you get from adding the library reference makes it worthwhile, as follows:
1. In the Visual Basic IDE, choose Tools> References to open the References dialog box:
The References dialog box lists all the object libraries installed on your system. If u e Microsoft Office, you’ll see libraries for familiar applications such as \ Excel, Outlook, and Word. Libraries that are currently loaded are listed at the top of the list (with check marks). The Visual Basic for Applications, Microsoft Project 9.0, and OLE Automation libraries are automatically referenced when you work with the VB IDE from Project 2000. –
2. Scroll down the list and select the library(ies) you want to use in your application. For our application, we need to add the Excel object library.
3. Click OK to close the References dialog box,
Now, you can access all the objects in the Excel object model. The VB Editor will correctly highlight code that uses incorrect methods or events.