How to Customize Custom Field Formula in VBA?

﹥>﹥吖頭↗ 提交于 2020-07-09 17:07:57

问题


I'm trying to modify a formula in a custom field in VBA. I currently have the following code:

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

The maxUID will change most likely each time I plan to use the macro. When attempting to execute the code, I get the error message:

External name not defined" for the "[% Complete]

Updated Code: Getting error on 2nd line of code still.

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

回答1:


Build the custom formula as a string and include it when calling the CustomFieldSetFormula method:

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


来源:https://stackoverflow.com/questions/48752841/how-to-customize-custom-field-formula-in-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!