Share via


Task Object

Project Developer Reference

Represents a task. The Task object is a member of the Tasks collection.

Using the Task Object

Use Tasks(Index), where Index is the task index number or task name, to return a single Task object. The following example prints the name of every resource assigned to every task in the active project.

  Dim Temp As Long, A As Assignment
Dim TaskName As String, Assigned As String, Results As String

For Temp = 1 To ActiveProject.Tasks.Count TaskName = "Task: " & ActiveProject.Tasks(Temp).Name & vbCrLf For Each A In ActiveProject.Tasks(Temp).Assignments Assigned = A.ResourceName & ListSeparator & " " & Assigned Next A Results = Results & TaskName & "Resources: " & _ Left$(Assigned, Len(Assigned) - Len(ListSeparator & " ")) & vbCrLf & vbCrLf TaskName = "" Assigned = "" Next Temp

MsgBox Results

Using the Tasks Collection

Use the Tasks property to return a Tasks collection. The following example displays the name of every task in the selection.

  Dim T As Task, Names As String

For Each T In ActiveSelection.Tasks Names = Names & T.Name & vbCrLf Next T

MsgBox Names

Use the Add method to add a Task object to the Tasks collection. The following example adds a new task to the end of the task list.

  ActiveProject.Tasks.Add "Hang clocks"

See Also