返回列表 上一主題 發帖

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

本帖最後由 a8350070 於 2012-5-26 11:04 編輯

試著在變動幅度最小的前提下修改

Option Explicit
Dim LastMin As Long

Private Sub Workbook_Open()
    Sheets("策略記錄").Cells(4, 2) = 10
    LastMin = Hour(Time) * 3600 + Minute(Time) * 60 + Second(Time)
   Call Timer
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
    Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkbook.Timer", , False
End Sub


Public Sub Timer()
    Dim Pos As Integer, i As Integer, RangeStr As String
        
    On Error Resume Next
    Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkbook.Timer" '每秒顯示
    Sheets("策略記錄").Cells(3, 2) = Time '將時間show至策略的b3欄位
    Dim HHMM As Integer
    HHMM = Hour(Time) * 100 + Minute(Time)
    If (HHMM < 845 Or HHMM > 1345) Then Exit Sub '營業時間才執行
    If Hour(Time) * 3600 + Minute(Time) * 60 + Second(Time) > LastMin + 30 Then '開始後做
        With Sheets("策略記錄")
            .Cells(4, 2) = .Cells(4, 2) + 1 '將變動行號加一行
            Pos = .Cells(4, 2)
            .Cells(Pos, 1) = Time
            .Cells(Pos, 2) = .Cells(2, 2)
            .Cells(Pos, 3) = .Cells(2, 3)
            .Cells(Pos, 4) = .Cells(2, 4)
            .Cells(Pos, 5) = .Cells(2, 5)
            .Cells(Pos, 6) = .Cells(2, 6)
            .Cells(Pos, 7) = .Cells(2, 7)
            .Cells(Pos, 8) = .Cells(2, 8)
            .Cells(Pos, 9) = .Cells(2, 9)
            .Cells(Pos, 10) = .Cells(2, 10)
           
         
        End With
   
        LastMin = Hour(Time) * 3600 + Minute(Time) * 60 + Second(Time)
    End If
End Sub
My Blog
http://blog.xuite.net/a8350070

TOP

        靜思自在 : 原諒別人就是善待自己。
返回列表 上一主題