一键导出Excel中的所有批注!
'作者:E精精
'功能:提取文件中的所有批注及相关信息
'---------------------------------------------------------
Sub 提取批注()
Dim rng As Range
Dim sht As Worksheet
Dim n As Long
Dim oComment As Object
Dim res(1 To 10000, 1 To 3)
For Each sht In ThisWorkbook.Sheets
For Each rng In sht.UsedRange
If Application.Version > 15 Then
Set oComment = rng.CommentThreaded
Else
Set oComment = rng.Comment
End If
If Not oComment Is Nothing Then
n = n + 1
res(n, 1) = sht.Name '表名
res(n, 2) = rng.Address(0, 0) '单元格地址
res(n, 3) = oComment.Text '批注
End If
Next
Next
With ThisWorkbook
With .Sheets("批注")
.UsedRange.ClearContents
.[A1:C1] = [{"工作表名称","地址","批注"}]
.Range("A2").Resize(n, 3) = res
For k = 2 To n + 1
.Hyperlinks.Add Anchor:=.Cells(k, 3), Address:="", _
SubAddress:="'" & .Cells(k, 1).Value & "'!" & .Cells(k, 2).Value, _
TextToDisplay:=.Cells(k, 3).Value
Next
End With
End With
End Sub
赞 (0)