2
votes

I'm using the BaselineWork1 timescaledata to contain a time phased calculation of resource work on individual tasks that I perform on a weekly basis. I want to zero out the previous week's calculation before I populate it with this week's calculation. Short of creating a loop to write zeros to the timescale data for each resource on each task is there a way to do this more efficiently? Could I make the beginning date and end date equal to the project's start and end date and time scale = seconds and the value to write equal to zero? For instance:

    For lngCnt1 = 1 To tskCounter.Resources.Count
        tskCounter.Assignments.Item(lngCnt1).TimeScaleData(StartDate:=ActiveProject.ProjectStart, EndDate:=ActiveProject.ProjectFinish, _
        Type:=pjAssignmentTimescaledBaseline1Work, _
        timescalunit:=pjTimescaleMinutes, Count:=1).Item(1).Value = 0
    Next lngCnt1

This doesn't seem to work as it only zeros out the baseline1 work field for the date corresponding to the project start date.

1

1 Answers

0
votes

To clear time-scaled work from anything but the forecast work field, you do need to loop through every assignment on every task. However, when it comes to the individual time-scale values, you can lump these together by year to reduce the iterations required.

Sub ClearBaseline1Work()

    Dim projStart As Date
    Dim projEnd As Date
    projStart = ActiveProject.ProjectStart
    projEnd = ActiveProject.ProjectFinish

    Dim tsk As Task
    For Each tsk In ActiveProject.Tasks
        Dim asn As Assignment
        For Each asn In tsk.Assignments
            Dim TSValues As TimeScaleValues
            Set TSValues = asn.TimeScaleData(projStart, projEnd, pjAssignmentTimescaledBaseline1Work, pjTimescaleYears)
            Dim tsv As TimeScaleValue
            For Each tsv In TSValues
                tsv.Clear
            Next tsv
            asn.Baseline1Work = 0
        Next asn
        tsk.Baseline1Work = 0
    Next tsk

End Sub

Remember that Baseline1 work values are not automatically updated at the assignment or task level; those values need to be explicitly cleared.