Vba 使用MS Project VB宏在指定级别获取自定义字段值

Vba 使用MS Project VB宏在指定级别获取自定义字段值,vba,ms-project,Vba,Ms Project,在我们的Project Enterprise安装中,有一个任务级别的自定义字段,名为计费率,但在计划中,它是在分配级别填充的,如下所示: Task Name Billing Rate ========== ============ Task 1 USD0.00 Resource 1 USD100.00 Resource 2 USD120.00 Task 2 USD0.00

在我们的Project Enterprise安装中,有一个任务级别的自定义字段,名为计费率,但在计划中,它是在分配级别填充的,如下所示:

Task Name         Billing Rate
==========        ============
Task 1              USD0.00
    Resource 1      USD100.00
    Resource 2      USD120.00
Task 2              USD0.00
    Resource 3      USD150.00
我想在VBA宏中访问计费率的值。但由于它是任务级别的自定义字段,我无法在task.Assignments中的assignment对象中访问它

我试过了

Assignment.Resource.GetField(FieldNameToFieldConstant("Billing Rate"))
但是得到错误:

<The argument is not valid.>

如何在作业级别访问此字段


另请注意,该字段可以在PowerBI中“BillingRate_T”的分配表下访问,但无法在Project VBA宏中访问。提前谢谢你

如果计费率数字已经作为资源表上每个资源的标准费率输入,您可以按任务使用以下各项:

Sub testBR()
Dim t As Task
Dim res As Resource
Dim asg As Assignment
Dim aN, br As String
Set t = ActiveSelection.Tasks(1)
For Each asg In t.Assignments
aN = asg.ResourceName
For Each res In ActiveProject.Resources
    If res.Name = aN Then
    br = res.StandardRate
    'do something with the 'br' variable before it is overwritten
    Debug.Print br
    End If
Next res
Next asg
End Sub
另一种使用前台处理的方法是,逐个任务执行任务:

Sub testBR1()
'start on the task name
Dim aBR As String
aBR = SelectTaskField(1, "Cost1 (Billing Rate)", True) 'change the reference column as needed
aBR = ActiveCell
'do something with the 'aBR' variable before it is overwritten
Debug.Print aBR
End Sub

如果计费率数字已作为资源表中每个资源的标准费率输入,则可以按任务使用以下各项:

Sub testBR()
Dim t As Task
Dim res As Resource
Dim asg As Assignment
Dim aN, br As String
Set t = ActiveSelection.Tasks(1)
For Each asg In t.Assignments
aN = asg.ResourceName
For Each res In ActiveProject.Resources
    If res.Name = aN Then
    br = res.StandardRate
    'do something with the 'br' variable before it is overwritten
    Debug.Print br
    End If
Next res
Next asg
End Sub
另一种使用前台处理的方法是,逐个任务执行任务:

Sub testBR1()
'start on the task name
Dim aBR As String
aBR = SelectTaskField(1, "Cost1 (Billing Rate)", True) 'change the reference column as needed
aBR = ActiveCell
'do something with the 'aBR' variable before it is overwritten
Debug.Print aBR
End Sub

查看(滚动到最底部…)一个解决方案似乎是找出哪个企业字段用于“账单费率”,然后直接查询。例如:
Assignment.EnterpriseNumber1
谢谢,但这些企业字段(例如EnterpriseCost1-EnterpriseCost10)实际上会显示在“监视”窗口中,并且这些字段不是自定义字段。查看(滚动到最底部…)一个解决方案似乎是找出哪个企业字段用于“计费率”直接询问。例如:
Assignment.EnterpriseNumber1
谢谢,但这些企业字段(例如EnterpriseCost1-EnterpriseCost10)实际上会显示在监视窗口中,而这些字段不是自定义字段。