Dim i, j As Single
Dim Min_Bar(1000, 6) As Variant 'Time, O,H,L.C,V
Dim O As Single
Dim H As Single
Dim L As Single
Dim C As Single
Dim V As Single
Dim NP As Single
Sub 關閉DDE自動交易系統()
On Error Resume Next
Application.OnTime Now + TimeValue("00:00:02"), "ThisWorkBook.ExeSelf", , False
End Sub
Sub 啟動DDE自動交易系統()
Dim k As Single
j = 2
Application.OnTime TimeValue("08:45:00"), "ExeSelf"
'Call ExeSelf
End Sub
Private Sub ExeSelf()
On Error Resume Next
i = i + 1
If i = 58 Then
Sheets(2).Cells(j, 1) = Time
Sheets(2).Cells(j, 2) = O
Sheets(2).Cells(j, 3) = H
Sheets(2).Cells(j, 4) = L
Sheets(2).Cells(j, 5) = C
Sheets(2).Cells(j, 6) = V
j = j + 1
i = 0: V = 0
O = Sheets(1).Cells(2, 2)
V = V + Sheets(1).Cells(2, 4)
H = O: L = O: C = O
Else
'以下判斷迴圈讓投資權重與投資標的物名稱設定,僅執行一次
C = Sheets(1).Cells(2, 2)
If C > H Then H = C
If C < L Then L = C
V = V + Sheets(1).Cells(2, 4)
' Sheets(2).Cells(i, 1) = Sheets(1).Cells(2, 2)
End If
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
Dim i, j As Single
Dim Min_Bar(1000, 6) As Variant 'Time, O,H,L.C,V
Dim O As Single
Dim H As Single
Dim L As Single
Dim C As Single
Dim V As Single
Dim NP As Single
Private Sub Workbook_Open()
j = 2
'Call ExeSelf
End Sub
Private Sub ExeSelf()
On Error Resume Next
i = i + 1
If i = 60 Then
Sheets(2).Cells(j, 1) = Time
Sheets(2).Cells(j, 2) = O
Sheets(2).Cells(j, 3) = H
Sheets(2).Cells(j, 4) = L
Sheets(2).Cells(j, 5) = C
Sheets(2).Cells(j, 6) = V
j = j + 1
i = 0: V = 0
O = Sheets(1).Cells(2, 2)
V = V + Sheets(1).Cells(2, 4)
H = O: L = O: C = O
Else
'以下判斷迴圈讓投資權重與投資標的物名稱設定,僅執行一次
C = Sheets(1).Cells(2, 2)
If C > H Then H = C
If C < L Then L = C
V = V + Sheets(1).Cells(2, 4)
' Sheets(2).Cells(i, 1) = Sheets(1).Cells(2, 2)
End If
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
'Application.OnTime Now + TimeValue("00:00:10"), "ThisWorkBook.ExeSelf", , False
End Sub
....略
End If
Application.OnTime Now + TimeValue("00:00:01"), "ExeSelf"
End Sub
回復 c_c_lai
有一點懂。簡單說就是把Modlue1最底下thisworkbook.ExeSelf改成指到ExSelf,就不會繞來繞去 ...
ddtggg 發表於 2018-9-12 11:36
Private Sub ExeSelf()
On Error Resume Next
i = i + 1
If i = 30 Then
Sheets(2).Cells(j, 1) = Time
Sheets(2).Cells(j, 2) = O
Sheets(2).Cells(j, 3) = H
Sheets(2).Cells(j, 4) = L
Sheets(2).Cells(j, 5) = C
Sheets(2).Cells(j, 6) = V
j = j + 1
i = 0: V = 0
O = Sheets(1).Cells(2, 2)
V = V + Sheets(1).Cells(2, 4)
H = O: L = O: C = O
Else
'以下判斷迴圈讓投資權重與投資標的物名稱設定,僅執行一次
C = Sheets(1).Cells(2, 2)
If C > H Then H = C
If C < L Then L = C
V = V + Sheets(1).Cells(2, 4)
' Sheets(2).Cells(i, 1) = Sheets(1).Cells(2, 2)
End If
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
Private Sub ExeSelf()
On Error Resume Next
i = i + 1
If i = 58 Then
Sheets(2).Cells(j, 1) = Time
Sheets(2).Cells(j, 2) = O
Sheets(2).Cells(j, 3) = H
Sheets(2).Cells(j, 4) = L
Sheets(2).Cells(j, 5) = C
Sheets(2).Cells(j, 6) = V
j = j + 1
i = 0: V = 0
O = Sheets(1).Cells(2, 2)
V = V + Sheets(1).Cells(2, 4)
H = O: L = O: C = O
Else
'以下判斷迴圈讓投資權重與投資標的物名稱設定,僅執行一次
C = Sheets(1).Cells(2, 2)
If C > H Then H = C
If C < L Then L = C
V = V + Sheets(1).Cells(2, 4)
' Sheets(2).Cells(i, 1) = Sheets(1).Cells(2, 2)
End If
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/) |