如何使用“名称”属性选择资源,然后返回另一个属性值

时间:2019-01-17 00:56:10

标签: vba ms-project

在MS Project中,我想编写VBA代码,该代码使用Resource.Name属性在资源表中找到资源,然后可以针对该资源返回值。例如,我想说的是找到名为“ John”的资源,然后能够返回其“ Initials”,“ Std.Rate”等。

For Each T In ActiveProject.Tasks

For Each asn In T.Assignments
    If asn.ResourceName = "John" Then  'Find the User Resources

     'Insert code here that finds John in the Resource sheet and returns his 
      'Std.Rate


    End If
Next asn
Next T

1 个答案:

答案 0 :(得分:1)

Assignment对象具有一个属性(Resource),该属性返回关联的Resource对象,这使这成为一项琐碎的任务:

For Each T In ActiveProject.Tasks

For Each asn In T.Assignments
    If asn.ResourceName = "John" Then  'Find the User Resources

     ' print resource's initials and standard rate 
     Debug.Print asn.Resource.Initials, asn.Resource.StandardRate

    End If
Next asn
Next T