none
how to apply actions to the tasks of a certain activity.PathPredecessor RRS feed

  • Question

  • I've realized that Task.PathPredecessor Property is Read-only Boolean. but how actions be done to path predecessors

    please read the following code :

    " through the code I want to change number 1 for  all path predecessors of activity t , activity t is the one with free float"

    Sub Macro30()
    Dim t As Task
    Dim p As Task
    For Each t In ActiveProject.Tasks
    If t.FreeSlack > 0 Then
    For Each p In t.PathPredecessor
    p.Number1 = 1
    Next p
    End If
    Next t
    End Sub

    Saturday, June 6, 2015 5:59 PM

All replies

  • elwishahi,

    You must be using Project 2013 because there is no PathPredecessor property associated with the Task object in earlier versions of Project. However, I think the following code will do what you need.

    Sub Macro30()
    Dim t As Task
    Dim p As TaskDependency
    For Each t In ActiveProject.Tasks
        If t.FreeSlack > 0 Then
            For Each p In t.TaskDependencies
                If p.From.UniqueID <> t.UniqueID Then p.From.Number1 = 1
            Next p
        End If
    Next t
    End Sub

    Hope this helps.

    John

    Saturday, June 6, 2015 6:53 PM
  • John,

    thank you

    {the application is needed for the predecessors from the start of the network not for the immediate predecessors only ( the application must be extended to the predecessors of predecessors and their predecessors)}

    I know that PathPredecessor is a new feature available only for Project 2013 and I'm using it.

    if I want the application for the immediate predecessors only, the code would be:

    Sub Macro30()
    Dim t As Task
    Dim p As Task
    For Each t In ActiveProject.Tasks
        If t.FreeSlack > 0 Then
            For Each p In t.PredecessorTasks
                p.Number1 = 1
            Next p
        End If
    Next t
    End Sub

    the only property that reaches predecessors from the start of the network till the activity is task.PathPredecessor but it is Boolean, which I can't use. how can we use it?

    Sunday, June 7, 2015 12:00 AM
  • elwishahi,

    Okay, you didn't specify you wanted the predecessor path all the way back to the start.

    I don't have Project 2013 so I can't research the PathPredecessor property but if it is a Boolean then in my mind it won't be very useful for what you are trying to do. However, I do have a suggestion. Years ago, MVP Jack Dahlgren wrote a macro to trace predecessors all the way back for a selected task. You can take a look at his macro (it's called Trace) on his webpage at: http://masamiki.com/project/macros.htm.

    Hope this helps.

    John

    Sunday, June 7, 2015 2:22 AM
  • I assuming you want to see all predecessors for the selected task? So once the correct task is selected, the following code will mark them all. You define a unique bar style and text style for marked tasks. You can also filter for a marked task.

    Sub Macro2()
    Dim Tsk As Task
        HighlightPredecessors Set:=True
        For Each Tsk In ActiveProject.Tasks
            If Not Tsk Is Nothing Then
                If Tsk.PathPredecessor Then
                    Tsk.Marked = True
                Else
                    Tsk.Marked = False
                End If
            End If
        Next Tsk
    End Sub


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Sunday, June 7, 2015 9:12 PM
    Moderator