如何使用停止按钮停止VBA中的Application.Ontime循环

时间:2017-03-18 14:44:33

标签: excel vba

您好我在Excel中有2个命令按钮,MarketOpen和MarketClosed。

单击MarketOpen时会发生以下循环:

Private Sub CommandButton1_Click()
MarketOpen
End Sub

Private Sub CommandButton2_Click()
Marketclosed
End Sub

Sub MarketOpen()
Application.OnTime Now + TimeValue("00:00:05"), "RefreshStocks"
End Sub

Sub RefreshStocks()
Application.CalculateFull
MarketOpen
End Sub

我试图用

结束循环
Sub MarketClosed()
Application.OnTime Now + TimeValue("00:00:05"), "RefreshStocks", , False
End Sub

但是,我遇到了运行时错误' 1004':

方法' Ontime'对象' _Application'失败。

谢谢!

0 个答案:

没有答案