Forum Discussion

Riele485's avatar
Riele485
Copper Contributor
Feb 04, 2022
Solved

VIsual Basic and MS Project

Is it possible to develop in Visual Basic within the MS Project feature to report on a set of tasks a percentage of the status of tasks, for example, how many percent are completed, how much percent ...
  • John-project's avatar
    John-project
    Feb 04, 2022

    Riele485 

    Here ya go. This is the macro:

    Sub StatusMetrics()
    'macro written for Riele485 by John-Project 2/4/2022
    Dim t As Task, PS As Task
    Dim Cnt As Single, Comp As Single, Lat As Single, OT As Single, Fut As Single
    For Each t In ActiveProject.Tasks
    If Not t Is Nothing Then
    If t.Summary = False Then Cnt = Cnt + 1
    If t.Status = pjComplete Then Comp = Comp + 1
    If t.Status = pjLate Then Lat = Lat + 1
    If t.Status = pjOnSchedule Then OT = OT + 1
    If t.Status = pjFutureTask Then Fut = Fut + 1
    End If
    Next t
    Set PS = ActiveProject.ProjectSummaryTask
    PS.Text1 = Cnt
    PS.Text2 = Format(Comp / Cnt * 100, "##.0") & " %"
    PS.Text3 = Format(Lat / Cnt * 100, "##.0") & " %"
    PS.Text4 = Format(OT / Cnt * 100, "##.0") & " %"
    PS.Text5 = Format(Fut / Cnt * 100, "##.0") & " %"
    MsgBox "Total tasks: " & PS.Text1 & vbCr _
    & "Completed: " & PS.Text2 & vbCr _
    & "Late: " & PS.Text3 & vbCr _
    & "On Time: " & PS.Text4 & vbCr _
    & "Future: " & PS.Text5, Title:="Status Metrics"
    End Sub

     

    And this is the result on a sample file:

    Pretty sweet huh?

    John

Resources