返回列表 上一主題 發帖

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

回復 127# areskevin
  1. Option Explicit

  2. Dim LastMin As String

  3. Private Sub Workbook_Open()
  4.     LastMin = "00:01:00"
  5.     Call Timer
  6. End Sub

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

  11. Public Sub Timer()
  12.     Dim Pos As Long, HHMM As Integer, col As Variant
  13.         
  14.     With Sheets("每分記錄")
  15.         HHMM = Hour(Now) * 100 + Minute(Now)
  16.         If (HHMM < 900 Or HHMM > 1333) Then Exit Sub
  17.    
  18.         .Cells(2, 4) = Now
  19.         Set col = Range(.Range("A5"), .Cells(5, .[A4].End(xlToRight).Column)).Find(Format(.Cells(2, 4), "M/D"), LookIn:=xlValues, LookAt:=xlWhole)
  20.         Pos = .Cells(Rows.Count, col.Column - 1).End(xlUp).Row + 1       '  均以其相對應之當日 (col) 為基準   (Pos = 6 : Long)
  21.         '  Pos = .Range("A" & Rows.Count).End(xlUp).Row + 1
  22.         .Cells(Pos, col.Column - 1) = Format(.Cells(2, 4), "HH:MM:SS")
  23.         .Cells(Pos, col.Column) = .Cells(2, 2)
  24.         .Cells(Pos, col.Column + 1) = .Cells(2, 3)
  25.     End With
  26.    
  27.     Application.OnTime Now + TimeValue(LastMin), "ThisWorkbook.Timer"
  28.     '  Application.OnTime Now + TimeValue("00:01:00"), "ThisWorkbook.Timer"
  29. End Sub
複製代碼
收收 Mail!
A2.png
2016-6-24 18:55

TOP

        靜思自在 : 要批評別人時,先想想自己是否完美無缺。
返回列表 上一主題