none
VBA Script for Cost Management RRS feed

  • Question

  • Hello Everyone,

    I need your help to set up a VBA on Project Online.

    The objective is : For each tasks which reach 100% progress the billing date switch to today's date. 

    Note that the field "billing date" has a initial planned date. 

    Currently I successfully wrote this script :

    Sub avancement()
    Dim tsk As Task
    Dim prj As Project
    Dim pos As Integer
    Set prj = Application.ActiveProject
    pos = 1
    For Each tsk In prj.Tasks
        If Not tsk Is Nothing Then
            If tsk.PercentComplete = 100 Then
                     prj.Tasks.Application.SetTaskField Field:="A_Date d_envoi", Value:=Now(), TaskID:=pos
            End If
        End If
        pos = pos + 1
    Next tsk

    End Sub

    However, you can notice that this script is applying only on current tasks progress and date and not for the futur task turning 100% progress. I mean that is not a automatic applying Macro

    Could someone help me please :)

    Best regards,

    Tuesday, July 9, 2019 7:07 PM

All replies

  • Hi,

    sorry, I don't understand "...  is applying only on current tasks progress and date and not for the future task turning 100% progress …"

    What I can see, is that you are setting the field value with

     If tsk.PercentComplete = 100 Then
                     prj.Tasks.Application.SetTaskField Field:="A_Date d_envoi", Value:=Now(), TaskID:=pos
     End If

    Does it work better when you just use

     If tsk.PercentComplete = 100 Then
                      tsk.SetTaskField Field:="A_Date d_envoi", Value:=Now()
     End If

    This should update your field "A_Date d_envoi" for each completed task.

    Regards
    Barbara


    Barbara Henhapl Blog (English/German) MVP

    Monday, July 15, 2019 7:40 AM
    Moderator