Excel暂停/等待macros

在我的Excel电子表格中,我有以下function,只要在两个未来合约之间发生某种差价,就会说“交易”

Function SayIt(c As Boolean, s As String) If c Then Application.Speech.Speak s SayIt = c End Function 

然后在工作表上我有:

 =SayIt(D15<=G6;REPT("trade ";1)) 

这样做效果很好,它会说“交易”,但每次价格在套利范围内移动,都会重复“贸易,贸易,贸易,贸易……”

现在我需要的是一个函数,它可以让价格允许价差套利的时候停止说“交易”,或者如果价格仍然在套利差价的范围内,它只会在20秒或1分钟后重复。

谢谢

好问题! ……..代码需要“记住”以前的呼叫被赋予True以避免重新发言。 我们可以用全局布尔值来做到这一点:

在标准模块中:

 Public Was_c_TrueBefore As Boolean Function SayIt(c As Boolean, s As String) If c And Not Was_c_TrueBefore Then Application.Speech.Speak s Was_c_TrueBefore = True End If If Not c Then Was_c_TrueBefore = False End If SayIt = c End Function 

因为只有一个Global,所以只能用于一个函数调用。