0

我们有一个用户定义的 VBA 函数。该函数返回一个结果,但也设置单元格的注释。它起作用了,我们得到了结果并设置了评论。

我们在此功能上包含了用户帮助。但是,如果用户单击 Fx 以获取帮助,Excel 会崩溃。如果我们注释掉单元格注释的设置,帮助就会起作用。包括"On Error"没有解决问题。

我们怀疑问题在于,当 Excel 从“Fx”帮助运行该函数时,它无法设置单元格注释——因为实际上没有单元格。

Excel 中是否有一个标志,我们可以使用它来检测 Excel 正在从“Fx”帮助屏幕运行该功能并跳过设置注释?

欢迎任何其他想法。

设置由我们的 UDF 调用的注释的代码:

Sub SetRangeComment(rng As Range, comment As String, intHeight As Long, intWidth As Long)

    On Error GoTo IgnoreError

    rng.ClearComments
    rng.AddComment comment
    If intHeight > 0 Then
        rng.comment.Shape.height = 13 * intHeight
    End If
    If intWidth > 0 Then
'    rng.comment.Shape.width = 6 * intWidth
    End If
    Exit Sub

IgnoreError:
    Exit Sub
End Sub
4

1 回答 1

0

就像是:

Public Function MyUdf()
    MsgBox TypeName(Application.Caller)
    MyUdf = "X"
End Function

但不建议使用 UDF 创建评论。

于 2015-06-30T19:13:15.617 回答