返回列表 上一主題 發帖

請問高手要將以下DDE 每分鐘記錄改為30秒自動記錄一次要怎改

請教c_c_lai,可以傳給我此檔嗎? thanks  a lot!

TOP

回復 23# c_c_lai


    收到,謝謝您熱心的分享,祝您財源滾滾...
stock

TOP

回復 21# usana642
1. 請將下列程式碼複製到 ThisWorkbook 模組內,並予儲存。
  1. Option Explicit
  2. Dim timerEnabled As Boolean    ' 判定開啟本工作表單的時段是否為開盤前啟動。
  3. Dim Pos As Integer             ' 將每隔 "多少時間" 處理時段,移到此處來處理。

  4. Private Sub Workbook_Open()
  5.     Pos = Sheets("策略記錄").Range("B" & Rows.Count).End(xlUp).Row
  6.     If (Pos < 11) Then Pos = 10
  7.     Sheets("策略記錄").Cells(4, 2) = Pos

  8.     If (Sheets("策略記錄").Range("B6").Value = "") Then Sheets("策略記錄").Range("B6").Value = "08:45:00"
  9.     If (Sheets("策略記錄").Range("B7").Value = "") Then Sheets("策略記錄").Range("B7").Value = "13:45:00"
  10.     If (Sheets("策略記錄").Range("B8").Value = "") Then Sheets("策略記錄").Range("B8").Value = "00:00:30"
  11.    
  12.     timerEnabled = False

  13.     Call timerStart      ' 程式一啟始,便去自動執行 timerStart
  14. End Sub

  15. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  16.     On Error Resume Next
  17.     Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkbook.Timer", , False
  18.    
  19.     Me.Save
  20. End Sub

  21. Public Sub Timer()
  22.     On Error Resume Next
  23.     If (TimeValue(Now) > Sheets("策略記錄").Range("B7").Value) Then Exit Sub
  24.    
  25.     If (TimeValue(Now) >= Sheets("策略記錄").Range("B6").Value) Then         ' 開盤、收盤時段設定
  26.         ' 盤中處理,將資料匯入寫入工作表單內儲存。

  27.         With Sheets("策略記錄")
  28.             .Cells(3, 2) = Time             ' 將時間 Show 至策略的 B3 欄位

  29.             Pos = Pos + 1                   ' 將變動行號加一行
  30.             .Cells(4, 2) = Pos

  31.             .Cells(Pos, 1) = Time
  32.             .Cells(Pos, 2).Offset(0).Resize(, 9) = .[B2:J2].Value
  33.         End With
  34.     End If
  35.         
  36.     Call timerStart
  37. End Sub

  38. Sub timerStart()
  39.     If timerEnabled Then
  40.         ' 第二次(含)以後均以設定之 "間隔時段" 來處理執行序的作業。
  41.         Application.OnTime (Now + Sheets("策略記錄").Range("B8").Value), "ThisWorkbook.Timer"
  42.     Else
  43.         timerEnabled = True
  44.         
  45.         ' 將第一次啟動時間更改為設定 "開盤時間"前,如果開啟 Excel 時,已經過了設定 "開盤時間",則一進入系統即直接去執行紀錄作業。
  46.         If (TimeValue(Now) <= Sheets("策略記錄").Range("B6").Value) Then
  47.             Application.OnTime (Sheets("策略記錄").Range("B6").Value), "ThisWorkbook.Timer"
  48.         Else
  49.             ' 系統剛連上 DDE 至資料匯入Excel工作表單,須有一個緩衝時段,
  50.             ' 這時如果馬上去抓取DDE資料,會有型態不符的錯誤訊息產生,並中斷執行序的作業。
  51.             Application.OnTime (Now + TimeValue("00:00:05")), "ThisWorkbook.Timer"
  52.         End If
  53.     End If
  54. End Sub
複製代碼
2. 工作表單內容如圖,請參考它與程式碼間的關係及運作。

3. 以上完成後,先將本專案儲存並離開。
4. 接下來先打開券商軟體
    (譬如:你製作的工作表單是跟哪一家券商連線的,如 EasyWin、eLeader、或其他券商連線軟體),
    然後啟動你製作的 "自動記錄每分鐘委買賣均值"  Excel,並同時連上券商連線軟體,就大功告成了!

希望它能助益於你,並能幫助你更上一層樓。

TOP

回復 20# c_c_lai


    c_c_lai 大大,我也需要這個檔案,因權限不足無法下載
可否寄到我的信箱,感謝熱心分享
stock

TOP

本帖最後由 c_c_lai 於 2012-6-25 17:34 編輯

回復 19# mead
找到了,已  E-Mail 過去了!

TOP

本帖最後由 c_c_lai 於 2012-6-25 08:42 編輯

回復 17# mead
附上一個可以隨你需求異動的 "自動記錄每分鐘委買賣均值",
以後你就沒有煩惱的事了!
自動記錄每分鐘委買賣均值.rar (13.96 KB)

P.S. 請將 Time() 裡的             .Cells(21, 2).Offset(0).Resize(, 9) = .[B12:J12].Value
更改成                                      .Cells(Pos, 2).Offset(0).Resize(, 9) = .[B2:J2].Value

TOP

本帖最後由 mead 於 2012-6-24 10:34 編輯
試著在變動幅度最小的前提下修改

Option Explicit
Dim LastMin As Long

Private Sub Workbook_Open ...
a8350070 發表於 2012-5-26 11:03

If Hour(Time) * 3600 + Minute(Time) * 60 + Second(Time) > LastMin + 30 Then '開始後做
這樣改  其要記錄的時間設定要減1
如30秒  就要加29而非30

TOP

謝謝a8350070  和c_c_lai 用心的解說
stock

TOP

感謝c_c_lai 大這麼詳細用心的解說

TOP

初來到這裡 真是高手如雲
看來可得好好學習了

TOP

        靜思自在 : 有時當思無時苦,好天要積雨來糧。
返回列表 上一主題