2012-12-11 55 views
2

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

在表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

是'Sheet1.ValDDE = Target.Column = 10'给您预期的结果?通常情况下,'A = B = C'将根据是否B = C或者...而给出A'True'或'False'... –

回答

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 
+0

HI bonCodigo.Please你能检查你的代码,因为似乎有错误,我似乎无法让它运行。 –

相关问题