我的代码运作良好。我的问题是,我希望能够关闭并跟踪变化。原因是,并非跟踪所有用户的更改。所有更改都会记录在不同的工作表中。请参阅下面的代码:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If ActiveSheet.Name = "TrackChanges_Record" Then Exit Sub
Application.EnableEvents = False
UserName = Environ("USERNAME")
NewVal = Target.Value
Application.Undo
oldVal = Target.Value
lr = Sheets("TrackChanges_Record").Range("A" & Rows.Count).End(xlUp).Row + 1
Sheets("TrackChanges_Record").Range("A" & lr) = Now
Sheets("TrackChanges_Record").Range("B" & lr) = ActiveSheet.Name
Sheets("TrackChanges_Record").Range("C" & lr) = Target.Address
Sheets("TrackChanges_Record").Range("D" & lr) = oldVal
Sheets("TrackChanges_Record").Range("E" & lr) = NewVal
Sheets("TrackChanges_Record").Range("F" & lr) = UserName
Target = NewVal
Application.EnableEvents = True
End Sub
答案 0 :(得分:0)
试试这个:
If ActiveSheet.Name = "TrackChanges_Record" or Environ("USERNAME") = "UserToSkip1" or Environ("USERNAME") = "UserToSkip2" Then Exit Sub