Share via


LinkPredecessors Method

Adds predecessors to a task.

Syntax

expression**.LinkPredecessors(Tasks, Link, Lag)**

*expression   *     Required. An expression that returns a Task object.

Tasks    Required Object. The Task or Tasks object specified becomes a predecessor of the task specified with *expression   *.

Link    Optional Long. A constant that specifies the relationship between tasks that become linked. Can be one of the following PjTaskLinkType constants: pjFinishToStart, pjStartToFinish, pjStartToStart, or pjFinishToFinish. The default value is pjFinishToStart.

Lag    Optional Variant. A string that specifies the duration of lag time between linked tasks. To specify lead time between tasks, use an expression for Lag that evaluates to a negative value.

The following example prompts the user for the name of a task and then makes the task a predecessor of the selected tasks.

Example

Sub LinkTasksFromPredecessor()

    Dim Entry As String     ' Task name entered by user
    Dim T As Task           ' Task object used in For Each loop
    Dim I As Long           ' Used in For loop
    Dim Exists As Boolean   ' Whether or not the task exists

    Entry = InputBox$("Enter the name of a task:")

    Exists = False          ' Assume task doesn't exist.

    ' Search active project for the specified task.
    For Each T In ActiveProject.Tasks
        If T.Name = Entry Then
            Exists = True
            ' Make the task a predecessor of the selected tasks.
            For I = 1 To ActiveSelection.Tasks.Count
            ActiveSelection.Tasks(I).LinkPredecessors Tasks:=T
            Next I
        End If
    Next T

    ' If task doesn't exist, display error and quit Sub procedure.
    If Not Exists Then
        MsgBox ("Task not found.")
        Exit Sub
    End If
    
End Sub

Applies to | Task Object, Tasks Collection Object

See Also | LinkSuccessors Method | Predecessors Property | PredecessorTasks Property | UnlinkPredecessors Method | UnlinkSuccessors Method