首页 > 解决方案 > 修改 CommentThreaded 时自动运行宏?

问题描述

我有一列,其单元格通过CommentsThreadedCommentThreaded对象进行评论。在另一个专栏中,我使用函数成功复制了这些线程的内容=GetComments(A1),如下图:

' Returns the concatenated string of parent and child comments for the specified input cell.
Function GetComments(SelectedCell As Range) As String
    Set CellComment = SelectedCell.CommentThreaded
    Dim Result As String
    If Not CellComment Is Nothing Then
        Result = CellComment.Author.Name & ": """ & CellComment.Text & """ " & vbNewLine & vbNewLine
        Dim ChildCount As Integer
        ChildCount = 1
        For Each ChildComment In CellComment.Replies
            Result = Result & "[Reply #" & ChildCount & "] " & ChildComment.Author.Name & ": """ & ChildComment.Text & """ " & vbNewLine & vbNewLine
            ChildCount = ChildCount + 1
        Next
    Else
        Result = "No Comments"
    End If
    GetComments = Result
End Function

示例输出为:John Doe: "My comment"

但是,我注意到当添加/编辑/删除评论时,使用该GetComments函数的输出单元格不会更新。我必须在输出单元格中手动重新运行该函数,以通过选择它并按下来更新其内容Enter

我已经尝试使用所有典型的事件处理程序,例如Worksheet.Change,SelectionChange等。修改评论时不会触发任何事件。手动强制VolatileCalculate. 这几乎就像CommentsThreaded根本不包含在工作簿事件中的 Add/Delete/Edit 方法一样。

这可能吗?谢谢!

标签: excelvba

解决方案


推荐阅读