简体   繁体   English

与Application.OnTime循环

[英]Loop with Application.OnTime

I have a program that is working but I am trying to improve it. 我有一个正在运行的程序,但我正在尝试对其进行改进。 The actual code is like this: 实际的代码是这样的:

Sub Main()
    frequencyinterval = Now + TimeValue("00:00:10")
    Application.OnTime frequencyinterval, "Sheet1.Subordinate"
End Sub

Sub Subordinate
    'Do some things
    Call Sheet1.Main 
End Sub

It seems to me that something like this would be better than calling Main from the sub. 在我看来,这样的事情比从sub调用Main更好。 Problem is that it shuts down Excel. 问题是它关闭了Excel。

Do While Cells(10, 1).Value = "Running"
    Frequencyinterval = Now + TimeValue("00:00:10")
    Application.OnTime frequencyinterval, "Sheet.Main"
Loop

I would appreciate any suggestions. 我将不胜感激任何建议。

I thought that recursive calls were bad. 我以为递归调用是不好的。 However, nothing else works. 但是,没有其他办法。 A wait within the do while stops the data feed of incomong stock prices. 稍等片刻,将停止进退的股价数据。

After the program has run for a few hours my computer goes into slow motion and later just locks up. 程序运行了几个小时后,我的计算机进入了慢动作状态,后来又锁定了。

Run Main once to start the loop 运行一次Main开始循环

Sub Main()

    If Cells(10, 1).Value = "Running" Then

        'do some things
        Call CheckTheThing()

        'Schedule the next run
        frequencyinterval = Now + TimeValue("00:00:10")
        Application.OnTime frequencyinterval, "Sheet1.Main"

    End If

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM