跟踪共享 Excel 文档中的更改

跟踪共享 Excel 文档中的更改

我有一个由多个用户共享的 Excel 工作表。我们习惯vlookup将更新的数据输入工作表中,以便所有用户都知道发生了什么变化。我们希望任何已更改的单元格都以黄色和红色字体突出显示。

我有此代码这可行,但我不知道如何在代码中添加黄色填充:

Private Sub Worksheet_Change(ByVal Target As Range) 
    Dim ws As Worksheet, ws2 As Worksheet 
    Dim i As Boolean Application.ScreenUpdating = False 'Create Change Log if one does not exist. 
    i = False 
    For Each ws In ThisWorkbook.Worksheets 
        If ws.Name = "Change Log" Then
            i = True 
            Exit For 
        End If 
    Next ws 

    If Not i Then Set ws2 = ThisWorkbook.Worksheets.Add 
        ws2.Visible = xlSheetHidden 
        ws2.Name = "Change Log" 
        ws2.Range("A1") = "Sheet" 
        ws2.Range("B1") = "Range" 
        ws2.Range("C1") = "Old Text Color" 
    Else Set ws2 = Sheets("Change Log") 
    End If 'Store previous color data in change log for rollback. 

    ws2.Range("A1").Offset(ws2.UsedRange.Rows.Count, 0) = Target.Worksheet.Name     
    ws2.Range("B1").Offset(ws2.UsedRange.Rows.Count - 1, 0) = Target.Address 
    ws2.Range("C1").Offset(ws2.UsedRange.Rows.Count - 1, 0) = Target.Font.Color 'Change font color to red.
    Target.Font.Color = 255 
    Application.ScreenUpdating = True 
End Sub 

答案1

您是否尝试过以下操作?

With .Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
End With

当然是将它运用到你的范围内。

答案2

添加以下内容Target.Font.Color=255

Target.Interior.Color = 65535

如果您使用我原帖中的回滚功能,则需要进行一些额外的修改来存储单元格填充颜色历史记录,以便可以回滚填充。如果您想要使用此功能,请告诉我,我会尝试发布修改后的代码版本。

相关内容