1

我有一个分配给 StopRecordingData 子的按钮来取消两个子,但它没有。时间表 False 似乎并没有取消 que 中的预定潜艇。

Dim NextTime As Double

Sub RecordData()
    Dim Interval As Double
    Dim cel As Range, Capture As Range

    Application.StatusBar = "Recording Started"
    Set Capture = Worksheets("Dashboard").Range("C5:K5") 'Capture this row 
    of data
    With Worksheets("Journal") 'Record the data on this worksheet
    Set cel = .Range("A2") 'First timestamp goes here
    Set cel = .Cells(.Rows.Count, cel.Column).End(xlUp).Offset(1, 0)
    cel.Value = Now
    cel.Offset(0, 1).Resize(1, Capture.Cells.Count).Value = Capture.Value
    End With
    NextTime = Now + TimeValue("00:01:00")
    Application.OnTime NextTime, "CloseWB"
End Sub

Sub CloseWB()
    Application.OnTime NextTime, "RecordData"
    ThisWorkbook.Close True
End Sub

Sub StopRecordingData()
    Application.StatusBar = "Recording Stopped"
    Application.OnTime NextTime, "RecordData", False
    Application.OnTime NextTime, "CloseWB", False
End Sub
4

1 回答 1

2

你必须要么

  • 最后使用 2 个逗号或
  • OnTime 方法的完整方法定义

因为OnTime方法的语法有 4 个参数,最后 2 个是可选的。

Application.OnTime EarliestTime,过程,[ LatestTime ],[ Schedule ]

此外,对于与时间相关的变量,更喜欢 DATE 而不是 DOUBLE。因此在顶部使用它。

Dim NextTime as Date

Sub StopRecordingData()
    Application.StatusBar = "Recording Stopped"
    Application.OnTime NextTime, "RecordData",, False
    Application.OnTime NextTime, "CloseWB",, False
End Sub

Sub StopRecordingData()
    Application.StatusBar = "Recording Stopped"
    Application.OnTime EarliestTime:=NextTime, Procedure:="RecordData", Schedule:=False
    Application.OnTime EarliestTime:=NextTime, Procedure:="CloseWB", Schedule:=False
End Sub
于 2019-01-24T05:16:39.243 回答