提问人:pearl 提问时间:10/28/2023 更新时间:10/28/2023 访问量:21
VBA 代码,用于了解修改 Excel 文件的每个人
vba code to know each person who modified an excel file
问:
我们有一个由我和一些同事修改的文件,我们的目的是显示每个人(在此文件中添加工作表的人,使用函数的人,删除工作表,....)使用VBA代码对该文件所做的更改
我使用了以下VBA代码,但它没有运行,实际上代码需要在更改之前创建,来自ExtendOffice https://www.extendoffice.com/documents/excel/3961-excel-track-changes-without-sharing-workbook.html#a1 的代码:
Option Explicit
Dim mStrRgAddress As String
Dim mStrRgValue As String
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Const xRg As String = "A1:Z1000"
Const xSheetName As String = "Record sheet" 'The sheet that you want to put the track changes, please change the sheet name to your own.
Dim strOld As String
Dim strNew As String
Dim strCmt As String
Dim xLen As Long
Dim xSheet As Worksheet
Dim xRgCell As Range
Dim xRgCell2 As Range
On Error Resume Next
Set xSheet = Application.Sheets.Item(xSheetName)
If mStrRgAddress <> "" Then
Set xRgCell = Range(mStrRgAddress)
If xRgCell.Text <> mStrRgValue Then
strCmt = mStrRgAddress & " : " & Format$(Now, "dd Mmm YYYY hh:nn:ss") & " by " & _
Application.UserName & Chr(10) & "Previous Text :- " & mStrRgValue
Set xRgCell2 = xSheet.Range("a1048576").End(xlUp)
If xRgCell2.AddressLocal = xSheet.Range("A1").AddressLocal Then
If xRgCell2.Value <> "" Then
Set xRgCell2 = xRgCell2.Offset(1, 0)
End If
Else
Set xRgCell2 = xRgCell2.Offset(1, 0)
End If
xRgCell2.Value = strCmt
End If
End If
If xSheet.Name = Sh.Name Then Exit Sub
mStrRgValue = Target.Text
mStrRgAddress = Target.AddressLocal(False, False, , True)
End Sub
非常感谢您的任何回复
答: 暂无答案
评论