我试图修改VBA中自定义字段中的公式。我目前有以下代码:
CustomFieldSetFormula FieldID:=pjCustomTaskNumber9
Formula = IIf(IIf([% Complete] = 100, 2, IIf([% Complete] < 100 And [Finish] > [Baseline Finish], 1, IIf([Unique ID] > maxUID, 3))))
CustomFieldProperties FieldID:=pjCustomTaskNumber9, Attribute:=pjFieldAttributeFormula, SummaryCalc:=pjCalcFormula, GraphicalIndicators:=True, AutomaticallyRolldownToAssn:=False
每次我打算使用宏时,maxUID
最有可能发生变化。尝试执行代码时,收到错误消息:
未定义外部名称&#34;对于&#34; [%完成]
更新的代码:第二行代码仍然出错。
customFormula = "IIf(IIf([% Complete] = 100, 2, IIf([% Complete] < 100 And [Finish] > [Baseline Finish], 1, IIf([Unique ID] > " & maxUID & ", 3))))"
CustomFieldSetFormula FieldID:=pjCustomTaskNumber9, Formula:=customFormula
CustomFieldProperties FieldID:=pjCustomTaskNumber9, Attribute:=pjFieldAttributeFormula, SummaryCalc:=pjCalcFormula, GraphicalIndicators:=True
答案 0 :(得分:3)
将自定义公式构建为字符串,并在调用CustomFieldSetFormula
方法时包含它:
Dim customFormula As String
customFormula = "IIf([% Complete] = 100, 2, IIf([% Complete] < 100 And [Finish] > [Baseline Finish], 1, IIf([Unique ID] > " & maxUID & ", 3)))"
CustomFieldSetFormula FieldID:=pjCustomTaskNumber9, Formula:=customFormula
CustomFieldProperties FieldID:=pjCustomTaskNumber9, Attribute:=pjFieldAttributeFormula, SummaryCalc:=pjCalcFormula, GraphicalIndicators:=True, AutomaticallyRolldownToAssn:=False