函数失败,封闭的工作簿

我有一个函数,根据字体的颜色,在一个范围内总结数字,如下所示。

Public Function SumByColor(pRange1 As Range, pRange2 As Range) As Double Application.Volatile Dim rng As Range Dim colorSumTot As Double colorSumTot = 0 For Each rng In pRange1 If rng.Font.Color = pRange2.Font.Color Then colorSumTot = colorSumTot + rng.Value End If Next SumByColor = colorSumTot End Function 

这在我做的Excel工作簿里面工作的很好。 我可以在同一工作簿内的工作表或其他工作表中select范围。

但是,如果我参考另一个工作簿,只要工作簿是公开的,就可以正常工作。 一旦我closures工作簿的单元格与我的函数引用其他工作簿给了我#VALUE! 错误。 如果我再次打开参考工作簿,数字会回来。

我以为我应该指出,即使closures参考工作簿,Excel函数也能正常工作。 (如SUM()AVERAGE()等)

为什么我不能closures工作簿?

谢谢。