行者

慢慢走,不要停
随笔 - 15, 文章 - 0, 评论 - 0, 阅读 - 3328
  博客园  :: 新随笔  :: 管理
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

ExcelVba 单元格历史记录(记录单元格变更历史)

Posted on   angury  阅读(159)  评论(0编辑  收藏  举报
复制代码
Public TrackChanges As Boolean

Sub ToggleCellHistory()
    TrackChanges = Not TrackChanges
    If TrackChanges Then
        MsgBox "单元格历史记录功能已开启。"
    Else
        MsgBox "单元格历史记录功能已关闭。"
    End If
End Sub

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If TrackChanges Then
        Dim cell As Range
        For Each cell In Target
            If cell.Comment Is Nothing Then
                cell.AddComment
            End If
            cell.Comment.Text Text:=Format(Now, "yyyy-mm-dd hh:mm:ss") & ": " & cell.Value & Chr(10) & cell.Comment.Text
        Next cell
    End If
End Sub
复制代码

 

点击右上角即可分享
微信分享提示