繁体   English   中英

Excel VBA UDF评论“从内部”

[英]Excel VBA UDF Comment “from the inside”

我有一个用户定义的函数,它将外部插件作为包装器调用并返回操作结果。

它在大多数情况下都有效,但是当外部库中的错误返回时,它有时会反映为#ERROR! BLAH BLAH BLAH等

出于审美原因,我试图找出一种方法来将注释添加到调用函数的单元格中,并返回“ - ”或某些指示性字符。

我似乎无法找到一种方法来查找对调用单元格的引用。

我希望有类似的东西:

If VarType(ret) = vbString And InStr("ret", "#ERROR!") > 0 Then
     <insert comment into Caller>
End If

有没有人有机会这样做?

谢谢!

使用Application.Caller

Function WrapError(ret As Variant) As Variant
    Dim CatchErr As Boolean

    If VarType(ret) = vbString Then
        If InStr(ret, "#ERROR!") = 1 Then
            CatchErr = True
        End If
    End If

    If CatchErr Then
        WrapError = [#VALUE!]
        Application.Caller.AddComment ret
    Else
        WrapError = ret
        If Not Application.Caller.Comment Is Nothing Then
            Application.Caller.Comment.Delete
        End If
    End If
End Function

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM