Tasks Collection Object

Project Developer Reference

Contains a collection of Task objects.

Example

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 names of every resource assigned to every task in the active project.

Visual Basic for Applications
  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

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

Visual Basic for Applications
  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.

Visual Basic for Applications
  ActiveProject.Tasks.Add "Hang clocks"

See Also