gpt4 book ai didi

excel - 使用 OnTime 宏停止潜艇的按钮不会停止

转载 作者:行者123 更新时间:2023-12-04 22:29:33 27 4
gpt4 key购买 nike

我有一个分配给 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

最佳答案

你必须要么

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

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

    Application.OnTime EarliestTime, Procedure, [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

    关于excel - 使用 OnTime 宏停止潜艇的按钮不会停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54339138/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com