将多个工作表链接到一个工作簿

时间:2016-01-26 15:55:00

标签: vba excel-vba excel

我有一个代码,我希望它链接到一个特定的工作表,它可以查看选项卡名称并捕获原始工作表中更改的数据。我不确定如何做到这一点,但对下面的任何见解都会很棒。

Dim vOldVal 'Must be at top of module
Private Sub Worksheet_Change(ByVal Target As Range)

Dim bBold As Boolean

If Target.Cells.Count > 1 Then Exit Sub
On Error Resume Next

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

If IsEmpty(vOldVal) Then vOldVal = "Empty Cell"
bBold = Target.HasFormula

With Sheet3 '# HERE I NEED THE HYPERLINK TO MY SHEET #"
.Unprotect Password:="Secret"
If .Range("A1") = vbNullString Then
            .Range("A1:E1") = Array("CELL CHANGED", "OLD VALUE", _
                "NEW VALUE", "TIME OF CHANGE", "DATE OF CHANGE")
End If
With .Cells(.Rows.Count, 1).End(xlUp)(2, 1)
   .Value = Target.Address
   .Offset(0, 1) = vOldVal
   With .Offset(0, 2)
        If bBold = True Then
         .ClearComments
         .AddComment.Text Text:= _
               "OzGrid.com:" & Chr(10) & "" & Chr(10) & _
                  "Bold values are the results of formulas"
        End If
       .Value = Target
       .Font.Bold = bBold
   End With
   .Offset(0, 3) = Time
   .Offset(0, 4) = Date
   '### HERE
   .Offset(0,5) = Environ("Username")
End With
.Cells.Columns.AutoFit
.Protect Password:="Secret"

End With

vOldVal = vbNullString
With Application

     .ScreenUpdating = True
 .EnableEvents = True
End With

On Error GoTo 0
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
vOldVal = Target
End Sub

0 个答案:

没有答案