dde链接单元格更改时的时间戳

时间:2012-12-11 12:08:05

标签: excel excel-vba vba

我在第11栏中有数据(dde链接)。我希望在第12列的第11列中数据发生变化时有一个时间戳。以下是我尝试但未按预期工作的一些代码?

表1中的

.....:

Private Sub Workbook_Open(ByVal Target As Range)
Sheet1.ValDDE = Target.Column = 10
End Sub
模块1中的

........:

Public ValDDE
Private Sub Worksheet_Calculate(ByVal Target As Range)
If VarType(ValDDE) = VarType(Target.Column = 10) Then
If ValDDE <> Cells(Target.Column, 12).Value = Now Then _
  MsgBox "New value : " & Target.Column = 11 _
  Else Exit Sub
Else: MsgBox "New value : " & Target.Column = 11
End If
ValDDE = Target.Column = 11
End Sub
Sub ddetrackchange()

End Sub

1 个答案:

答案 0 :(得分:0)

我建议您删除'计算'方法,因为这是令人讨厌的性能减缓 horcrux

请使用worksheet changed event尝试以下操作。如果只检测一个单元格,则无需检查范围为for loop的每个单元格。

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim myRng As Range
    Set myRng = Range("D2") 'change according to yours
    If Target.Application.DDEAppReturnCode = True 'this check the dde link updates specifically
      If Target.Address = myRng.Address Then        
         'change time in some other cell
         Range("E2").value = now()
      else
      'do something else
      End If
    else
    'do something else
    End If
End Sub