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.
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 2013.
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 do not set the Visible property to True , the Project application operates in the background without being visible.
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 2013 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.
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 do not 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