我正在尝试跟踪多人使用的Excel文件中所做的更改。到目前为止,我已经构建了模型(在stackoverflow的帮助下)在activeworkbook.path&中保存了自己的版本。 “\版本控制”。
文件打开时保存副本并命名为:date&时间& activeworkbook.name
目前,它会查看一个范围以确定是否相交然后返回工作表x单元格y中的新值。如何编写代码以允许它打开最新保存的备份,并在表格x cell z中为我提供旧版本的值?
我的代码:
跟踪变化:
Private Sub Worksheet_Change(ByVal Target As Range)
If Sheets("UserLog").Cells(1, 24) = IsBlank Then Exit Sub
Dim strAddress As String
Dim val
Dim dtmTime As Date
Dim Rw As Long
If Intersect(Target, Range("CheckRange5")) Is Nothing Then Exit Sub
dtmTime = Format(Now(), "YYYY-MM-DD HH:MM:SS")
val = Target.Value
strAddress = Target.Address
Rw = Sheets("UserLog").Range("D" & Rows.Count).End(xlUp).Row + 1
With Sheets("UserLog")
.Cells(Rw, 4) = strAddress
.Cells(Rw, 5) = val
.Cells(Rw, 6) = dtmTime
.Cells(Rw, 7) = Environ("Username")
.Cells(Rw, 8) = "SCI - SDBD"
End With
ActiveWorkbook.Save
End Sub
保存文件:
Private Sub Workbook_Open()
Dim MyDate
MyDate = Date
Dim MyTime
MyTime = Time
Dim TestStr As String
TestStr = Format(MyTime, "hhmmss")
Dim Test1Str As String
Test1Str = Format(MyDate, "YYYY-MM-DD")
xxPath = ActiveWorkbook.Path
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:=xxPath & "\Version Control" & "\" & Test1Str & " " & TestStr & " " & ActiveWorkbook.Name
ActiveWorkbook.Save
Application.DisplayAlerts = True