公式经常使用范围,例如
=If(A1=2,"Yes","No")
在此示例中,A1
被注入Range
对象,该对象代表单元格A1
。但是,假设我有一些来自某个班级的对象。我该如何将其注入公式中?
目前,我最好的选择(相当糟糕)是使用集合和UDF:
Public FormulaVariables as Collection
Public Function getVar(key as string) as object
set getVar = FormulaVariables(key)
end function
Public Sub addVar(key as string, obj as object)
if FormulaVariables is nothing then set FormulaVariables = new Collection
FormulaVariables.add obj,key
end sub
我可以叫addVar("someCoolId",myObject)
,然后使用类似以下的公式:
=If(checkSomething(getVar("someCoolId")),"Yes","No")