Sub 載入日盛DDE()
With ThisWorkbook.Worksheets("外部資料")
.Cells.Clear
'寫入時間
.Range("B1").Formula = "=DDEEXCEL|FUTURETXF" & NearMonth & NearYear & "!時間"
end with
Dim NewVolume As Long
Dim nRow As Long
With ThisWorkbook.Worksheets("台指期DDE")
If IsNumeric(.Range("A1")) = True Then
NewVolume = .Range("A1")
If NewVolume <> TXoldVolume Then
'將即時價差及台指期即時成交價逐行寫入各欄
With ThisWorkbook.Worksheets("繪圖資料")
nRow = .Range("B65536").End(xlUp).Row
If nRow = 1 And .Range("B1") = "" Then
.Cells(1, 1) = Time
.Cells(1, 2) = ThisWorkbook.Worksheets("外部資料").Range("C3") '台指期價格
With ThisWorkbook.Worksheets("外部資料")
If IsNumeric(.Range("C3")) And IsNumeric(.Range("C11")) And _
IsNumeric(.Range("C19")) Then
ThisWorkbook.Worksheets("繪圖資料").Cells(1, 5) = _
CalSpread(.Range("C11"), .Range("C19"), .Range("C3")) '目前價差
End If
End With作者: 沙拉油 時間: 2010-5-13 23:40
VBA碼
Sheet1 (Sheet4)
Private Sub CommandButton1_Click()
download
End Sub
Module1
Private ChartStr(5) As Long
Sub download()
Dim R1 As Range, R2 As Range
If Time >= TimeValue("13:45:06") Then End '13:45後停止程式
If Time < TimeValue("08:45:00") Then
ChartStr(5) = 1
Application.OnTime TimeValue("08:45:00"), "download" '08:45前程式設定於08:45執行 "download"程式
Exit Sub
Else
ChartStr(1) = [B65536].End(xlUp).Row
Application.OnTime Now + TimeValue("00:00:05"), "download"
End If
With Sheet1
ar1 = Array([D3], [E3], [L3])
.[B65536].End(xlUp).Offset(1, 0).Resize(, 3) = ar1
.[A65536].End(xlUp).Offset(1, 0) = Time