Application.SetTaskField method (Project)

Sets the value of a task field specified by the name of the 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 Project creates a task when 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

Remarks

To set a task field by ID, use the SetTaskFieldByID method.

Example

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

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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.