Application object (Project)

Represents the entire Project application. The Application object contains:

  • Application-wide settings and options (many of the options in the Options dialog box on the Tools menu, for example).

  • Properties that return top-level objects, such as ActiveCell, ActiveProject, and so forth.

  • Methods that act on application-wide elements, such as views, selections, editing actions, and so forth.

Using the Application Object

Use the Application property to return an Application object in Project . The following example applies the Windows property to the Application object.

Application.Windows("Project1.mpp").Activate

Using Project From Another Application: Late Binding

The following example creates the Microsoft Project Application object at run time, creates a new project, adds a task, saves the project, and then closes the Project . For example, copy and paste the CreateProject_Late macro to the ThisDocument module in the Visual Basic Editor (VBE) of Word.

Note

Because the application queries the MSProject.Application type library only at run time, Microsoft IntelliSense is not available and performance is relatively poor with late binding. Scripting languages, such as JavaScript and VBScript, require late binding. VBScript supports only the generic Object and Variant data types. For better performance in VBA and other compiled languages, you should use early binding by setting a reference to the Project type library.

Sub CreateProject_Late() 
    Dim pjApp As Object 
    Set pjApp = CreateObject("MSProject.Application") 
    pjApp.Visible = True 
    pjApp.FileNew 
    pjApp.ActiveProject.Tasks.Add "Hang clocks" 
    pjApp.FileSaveAs "Clocks.mpp" 
    pjApp.FileClose 
    pjApp.Quit 
End Sub

If you don't set the Visible property to True, the Project application operates in the background without being visible.

Using Project From Another Application: Early Binding

Early binding has better performance because it loads the type library at design time. To use early binding, you must set a reference to the Project application from the application you are working in. For example, in the VBE for a Word document, click References on the Tools menu, scroll through the Available References list, and then choose the Microsoft Project 15.0 Object Library checkbox.

The following example opens a project from another application such as Excel , adds a task, and then saves and closes the project.

Sub ModifyProject_Early() 
    Dim pjApp As MSProject.Application 
    Set pjApp = New MSProject.Application 
    pjApp.Visible = True 
    pjApp.FileOpen "Clocks.mpp" 
    pjApp.ActiveProject.Tasks.Add "Wind clocks" 
    pjApp.FileSave 
    pjApp.FileClose 
    pjApp.Quit 
End Sub

Remarks

Important

For application-level events, register event handlers after you set Application.Visible = True.

If you instantiate Project from another application and register an application-level event before setting the Visible property of the Application object to True, the properties and methods of child objects of Application don't work. For example, Application.ActiveProject.Name is not accessible.

Many of the properties and methods that return the most common user-interface objects, such as the active project—represented by the ActiveProject property—can be used without the Application object qualifier. For example, instead of writing Application.ActiveProject.Visible = True you can write ActiveProject.Visible = True

Events

Methods

Name

Properties

Name

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.