Share via


WBSPredecessors Property

Returns the WBS codes of the predecessors of the selected task, separated by the list separator. Read-only String.

Example

This example queries the user for a task ID and then provides a more user-friendly breakdown of its predecessors' WBS codes.

Sub EnumeratePredecessors()
    Dim Task As Task
    Dim PredTasks As Tasks
    Dim ID As Long
    Dim Predecessors As String
    Dim List As String
    Dim Count As Integer
    
    ID = CLng(InputBox$("Enter the ID number of the task you wish to examine:"))
    
    Set Task = ActiveProject.Tasks(ID)
    Set PredTasks = Task.PredecessorTasks
    Predecessors = Task.WBSPredecessors
    Count = 1
    
    If PredTasks.Count = 0 Then
        List = "Task " & Task.UniqueID & ", " & Task.Name & ", has no predecessors."
    Else
        List = "Predecessors to task " & Task.UniqueID & ", " & Task.Name & ":" & vbCrLf & vbCrLf
        Do While InStr(Predecessors, ListSeparator) <> 0
            List = List & PredTasks(Count).Name & ": " & Mid$(Predecessors, 1, InStr(Predecessors, ListSeparator) - 1) & vbCrLf
            Predecessors = Right$(Predecessors, Len(Predecessors) - InStr(Predecessors, ListSeparator))
            Count = Count + 1
        Loop
        List = List & PredTasks(Count).Name & ": " & Predecessors
    End If
    
    MsgBox List
    
    Set PredTasks = Nothing
    Set Task = Nothing
End Sub

Applies to | Task Object, Tasks Collection Object

See Also | WBSCodeMaskEdit Method | WBSCodeRenumber Method | WBSSuccessors Property