Use 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