经常跟表格打交道的朋友是否遇到过需要查看单元格批注的情况?正常情况下都是鼠标悬停在单元格来查看,当批注量比较多时一个个单元格悬停查看太麻烦了。今天给大家分享一个全能兼容的VBA自定义函数 GetComments,一个公式直接提取单元格批注文本。一键提取单元格批注内容
Public Function GetComments(ByVal 单元格 As Range) As String Application.Volatile True On Error Resume Next Dim result As String result = "" Dim cell As Range Set cell = 单元格.Cells(1, 1) If Not cell.Comment Is Nothing Then result = cell.Comment.text Else Dim threadedComment As Object Set threadedComment = cell.CommentThreaded If Not threadedComment Is Nothing Then result = threadedComment.text End If End If GetComments = result On Error GoTo 0End Function
五、使用方法
- 打开 Excel,按
Alt+F11 打开 VBA 编辑器;