Application.SetTaskField Method

Project Developer Reference

Sets the value of a task field.

Syntax

expression.SetTaskField(Field, Value, AllSelectedTasks, Create, TaskID, ProjectName)

expression   A variable that represents an Application object.

Parameters

Name Required/Optional Data Type Description
Field Required String The name of the task field to set.
Value Required String The value of the task field.
AllSelectedTasks Optional Boolean True if the value of the field is set for all selected tasks. False if the value is set for the active task. The default value is False.
Create Optional Boolean True if Microsoft Office Project 2007 should create a new task if the active cell is on an empty row. The default value is True.
TaskID Optional Long The identification number of the task containing the field to set. If AllSelectedTasks is True, TaskID is ignored.
ProjectName Optional String If the active project is a consolidated project, specifies the name of the project for the task specified by TaskID. If TaskID is not specified, ProjectName is ignored. The default value is the name of the active project.

Return Value
Boolean

Example
The following example first changes the task field "Name" of Task ID 3 to "New Task Name", and then changes it back to the original name.

Visual Basic for Applications
  Sub Set_TaskField()
Dim T As Task
Set T = ActiveProject.Tasks(3)
' Save the task name
OldName = T.GetField(pjTaskName)

ViewApply Name:="&Gantt Chart"
SetTaskField Field:="Name", Value:="New Task's Name", TaskID:=3
SetTaskField Field:="Name", Value:=OldName, TaskID:=3

End Sub

See Also