问题
I need to create a basic user audit trail in Excel 2010 tracking changes to certain cells by different users not signing into a PC (shared PC)
回答1:
The following macro monitors changes to cells A2 thru A20
If a user changes any of these cells, the username and date are recorded in the cell's comment
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Intersect(Target, Range("A2:A20")) Is Nothing Then Exit Sub
Application.EnableEvents = False
Dim s As String
s = Now & vbCrLf & Environ("UserName")
With Target
.ClearComments
.AddComment s
End With
Application.EnableEvents = True
End Sub
来源:https://stackoverflow.com/questions/22948585/create-user-audit-trail-in-microsoft-excel-2010