Share via


Understanding the Project Object Model

The Application object contains all Microsoft® Project objects. Each Project object contains summary information, tasks, and resources. The Project object represents an individual project or a collection of projects. In addition, Project objects are parent objects of Windows, Tasks, Resources, and Calendars collections.

Project objects can be referenced using the Application property ActiveProject, by referring to the project's index value or by naming the project:

Sub ProjectRefs() 
MsgBox ActiveProject 
MsgBox Projects(1).Name 
MsgBox Projects("Project1").ProjectStart 
End Sub 

Project Object Properties

Fields in the project summary task record can be browsed or edited using Project object properties. The following examples return information from these fields. After running the macro, review the information on the Schedule tab in the Tools Options dialog box.

Sub ProjectProperties() 
MsgBox ActiveProject.ActualCost 
MsgBox ActiveProject.Author 
MsgBox ActiveProject.AutoLinkTasks 
ActiveProject.AutoLinkTasks = False 
End Sub 

Other properties are useful for returning active views, tables, and filters. Make sure to run the following procedure from a task or resource view:

Sub ProjectCurrentProperties() 
MsgBox ActiveProject.CurrentView 
MsgBox ActiveProject.CurrentTable 
MsgBox ActiveProject.CurrentFilter 
End Sub 

Project Object Methods

The Tasks method returns a task or tasks in a Project object*.* To iterate through tasks try the following two routines:

Sub TaskDisplay() 
Dim i As Integer 
Dim t As Variant 

For i = 1 To ActiveProject.Tasks.Count 
MsgBox ActiveProject.Tasks(i).Name 
Next i 
For Each t In ActiveProject.Tasks 
MsgBox t.Name 
Next t 
End Sub 

The Resources method returns a resource or resources in a Project object:

Sub ResourceNameDisplay() 
Dim r as Variant 
For Each r in ActiveProject.Resources 
MsgBox r.Name 
Next r 
End Sub 

The TaskViewList, TaskTableList, TaskFilterList, ResourceViewList, ResourceTableList, and ResourceFilterList methods return available views, tables, and filters in a project. The following example displays a list of available task views:

Sub ListViews() 
Dim strViewList As String 
Dim i As Integer 
NL = Chr$(13) & Chr$(10) 
strViewList = "Task Views:" & NL 

For i = 1 To ActiveProject.TaskViewList.Count 
strViewList = strViewList & ActiveProject.TaskViewList(i) & NL 
Next i 

MsgBox strViewList 
End Sub 

See Also

Working with Microsoft Project Objects | Understanding the Project Application Object