vbams-project

How to get task hours in resources usage view in ms project by VBA?


I want to get one of these values (108,10,21...) from resources usage and do some operations on it in VBA macro (for exemple add a number to it and put it in another cell ) but i don't know how , I tried to learn by record macro but it didn't work. I hope my question is clear if not just ask for clarify and I will do it .

enter image description here


Solution

  • What you are asking for is the work at the assignment level, by resource. For example:

    Sub GetAssignmentWorkByResource()
    
        Dim r As Resource
        For Each r In ActiveProject.Resources
            Dim a As Assignment
            For Each a In r.Assignments
                Debug.Print r.Name, a.Task.Name, a.Work / 60 & " h"
            Next a
        Next r
        
    End Sub
    

    See Resource object, Assignment object