gpt4 book ai didi

vba - 准时申请

转载 作者:行者123 更新时间:2023-12-04 21:02:22 25 4
gpt4 key购买 nike

我的 OnTime 遇到一些问题-vba 中的方法。该代码应该每 30 分钟运行一次,但不知何故,它会在其间运行几次。我假设这是因为几个 OnTime当我重置并重新运行代码时,-methods 可能正在运行。所以我想杀死准时功能但得到错误。下面是我的代码:

初始代码:

Sub autorefresh()
dim timetorun

timetorun = Now + TimeSerial(0, 30, 0)

Application.OnTime timetorun, "manager" 'this runs the macro manager which
'runs several other macros and in
'the end calls this macro again in
'order to reset the timetorun counter
End Sub

如果需要,我修改了以下代码以重置准时。
Public timetorun As Date    'so that timetorun can be used in both the functions

Sub autorefresh()

timetorun = Now + TimeSerial(0, 30, 0)
Application.OnTime timetorun, "manager"

End Sub

Sub killontime()

Application.OnTime earliesttime:=timetorun, procedure:="manager", schedule:=False '<~~this line gives the error

End Sub

最佳答案

谢谢大家...在 R3uk 和 eirikdaude 的建议下,以下代码完美运行:

Public timetorun As Double

Sub autorefresh()

timetorun = Now + TimeSerial(0, 30, 0)

Application.OnTime timetorun, "manager"

End Sub


Sub killontime()

Application.OnTime timetorun, "manager", , False

End Sub

关于vba - 准时申请,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33750773/

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