宏运行RTD更新

时间:2013-02-05 08:23:54

标签: excel vba rtd

我的问题如下:

我正在运行一个倒计时从900到0的实时数据服务器。一旦倒计时达到5我想要excel复制工作表(RTD_NEWS)中的范围(B2到B61)并将其粘贴到新工作表中作为价值观。

问题是我的宏在剩余时间点击时不会自动执行此操作5.如果我在单元格为5时点击运行它会正确运行。

我已经制作了2个宏,其中第一个需要按照我的意愿运行,如果我手动更改单元格而不是RTD链接,则第二个工作。

第一个宏是:

Function Test()
Dim TimeRemaining As Long
TimeRemaining = ActiveWorkbook.Sheets("RTD_NEWS").Range("D2")
If TimeRemaining = 5 Then
Application.Goto ActiveWorkbook.Sheets("RTD_NEWS").Range("B2", "B61")
Selection.Copy
Worksheets.Add
Application.Goto ActiveSheet.Range("B21")
ActiveCell.PasteSpecial (xlPasteValues)
Application.Wait Now + TimeValue("00:00:06")
End If
End Function

第二个宏是:

Sub auto_open()
   ' Run the macro DidCellsChange any time a entry is made in a
   ' cell in Sheet1.
   ThisWorkbook.Worksheets("RTD_NEWS").OnEntry = "DidCellsChange"
End Sub
Sub DidCellsChange()
  Dim KeyCells As String
   ' Define which cells should trigger the KeyCellsChanged macro.
   KeyCells = "D2"
   ' If the Activecell is one of the key cells, call the
   ' KeyCellsChanged macro.
   If Not Application.Intersect(ActiveCell, Range(KeyCells)) _
   Is Nothing Then KeyCellsChanged
End Sub
Sub KeyCellsChanged()
   Dim Cell As Object

    For Each Cell In ActiveWorkbook.Sheets("RTD_NEWS").Range("D2")
   If Cell = "200" Then

Application.Goto ActiveWorkbook.Sheets("RTD_NEWS").Range("B2", "B61")
Selection.Copy
Worksheets.Add
Application.Goto ActiveSheet.Range("B21")
ActiveCell.PasteSpecial (xlPasteValues)
Application.Wait Now + TimeValue("00:00:06")
   End If
   Next Cell
End Sub

0 个答案:

没有答案
相关问题