我继承了Excel 2013/2016的VSTO加载项项目,该项目的运行方式很奇怪。外接程序由一个C#后端组成,在该后端之间有一个VBA UDF层。
VBA(摘要):
Option Explicit
Private addInWrapper as Object
Private addin As Office.COMAddIn
Private Function GetAddIn() As Object
If (addInWrapper Is Nothing) Then
For Each addin In Application.COMAddIns
If (addin.Description = "OurAddInId") Then
Set addInWrapper = addin.Object
End If
Next
End If
If (addInWrapper Is Nothing) Then
MsgBox "Unable to find our Add-In", vbOKOnly + vbExclamation, "AddIn"
End If
Set GetAddIn = addInWrapper
End Function
Public Function OurFunction(arg1 As Variant, arg2 As Variant, arg3 As Variant) As Variant
On Error GoTo errHandler
OurFunction = GetAddIn.OurVstoMethod(arg1, arg2, arg3) ' affected line
Exit Function
errHandler:
Call MsgBox(Err.Description, vbExclamation)
End Function
从像{=OurFunction(...)}
(CSE /数组样式的公式)那样的单元格公式调用时,此代码失败,并带有“无法对空引用执行运行时绑定”。
奇怪的是,当断点到位并且代码在VBA调试器中逐步执行时,不会发生此错误;我设法跟踪了这一点(通过添加一些行号并在On Error
MsgBox中使用Erl)来调用OurVstoMethod
-但是,当公式将其作为普通公式{{1}调用时一切正常。在这种情况下,更改CBA行为的CSE公式是否有什么特别之处?