excel - 有没有办法使用宏跟踪共享工作簿中发生的更改?
问题描述
我有一个可供多个用户访问的共享主表。我想使用宏跟踪用户所做的更改,然后保留第一个用户所做的更改并给其他用户一个 msgbox,说明已经进行了更改。现在有功能区中的“共享工作簿”选项中提供了一个选项,其中显示“询问我哪些更改获胜”,但我希望第一个用户在不弹出任何对话框的情况下进行更改。我尝试了“正在保存的更改”选项,但它没有按预期工作。有没有办法使用宏来做到这一点?如果是,如何?
解决方案
Private Sub Worksheet_Change(ByVal Target As Range)
Set FindCell = Worksheets("Track Changes").Columns(2).Find(Target.Address, LookIn:=xlValues)
R = Worksheets("Track Changes").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
If FindCell Is Nothing Then
With Worksheets("Track Changes")
.Cells(R, 1).Value = Date
.Cells(R, 2).Value = Target.Address
.Cells(R, 3).Value = Application.UserName
If Target.Value = "" Then
.Cells(R, 4).Value = "Empty cell"
Else
.Cells(R, 4).Value = Target.Value
End If
End With
Else
firstAddress = FindCell.Address
Do
If FindCell.Offset(0, -1).Value = Date Then
MsgBox "Changes already made by " & FindCell.Offset(0, 1).Value & _
vbNewLine & "Changes: " & FindCell.Offset(0, 2).Value
Exit Sub
End If
Set FindCell = Worksheets("Track Changes").Columns(2).FindNext(FindCell)
Loop While Not FindCell Is Nothing And FindCell.Address <> firstAddress
With Worksheets("Track Changes")
.Cells(R, 1).Value = Date
.Cells(R, 2).Value = Target.Address
.Cells(R, 3).Value = Application.UserName
If Target.Value = "" Then
.Cells(R, 4).Value = "Empty cell"
Else
.Cells(R, 4).Value = Target.Value
End If
End With
End If
End Sub
推荐阅读
- python - 使用 Tkinter 的“pip install Module”程序
- whitespace - 带有乘法运算符的标准 ML Foldl/Foldr 函数?
- python - 转换为日期时间 Python 时的错误处理
- mysql-workbench - 添加列时如何将 SRID 4326(空间类型)添加到 Workbench?
- python - RandomWalker 分割算法的分割结果与初始种子相同
- arrays - Error NgFor 仅支持绑定到 Iterables,例如 Arrays。如何将 JSON 对象转换为数组对象?
- javascript - IFormContext 只引用了一个类型,但在这里用作值
- android - 当我可以使用静态函数时,为什么还要使用 Dagger 或 Hilt DI?
- javascript - 我可以在没有 npm 或 node.js 的情况下使用 .dotenv 库作为 HTML 脚本导入吗?
- ios - 防止 SwiftUI 动画覆盖嵌套的 withAnimation 块