给Excel添加一个获取单元格批注的公式

通过VBA在Excel中添加一个获取单元格批注的公式,代码如下:

Function ExtractCommentWithoutAuthor(rng As Range) As String

    Dim commentText As String

    ' 检查单元格是否有批注

    If Not rng.comment Is Nothing Then

        ' 提取批注文本并去除作者信息

        commentText = rng.comment.Text

        commentText = Replace(commentText, rng.comment.Author & ":", "")

        ExtractCommentWithoutAuthor = commentText

    Else

        ExtractCommentWithoutAuthor = ""

    End If

End Function

效果演示:

在单元格输入公式


输入公式


结果

注:1、开启Excel开发工具栏的方法:点击文件➡选项➡自定义功能区➡勾选开发工具,确定即可

开启Excel开发工具栏

2、打开VBA编辑框快捷键:Alt+F11

3、示例文件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容