我不明白为什么我错误地将这行 Application.Wait (以黄色突出显示)?
Sub Wait_Random()
Dim Low As Double
Dim High As Double
Low = 90 '<<< CHANGE AS DESIRED
High = 126 '<<< CHANGE AS DESIRED
r = Int((High - Low + 1) * Rnd() + Low)
Application.Wait Now + TimeValue("00:00:" & CStr(r))
End Sub
我发现问题是这段代码正在尝试“为一串字符添加一个数字”。但我迷路了!在此先感谢;)
答案 0 :(得分:1)
这是因为您的r
变量总是大于59
秒。 (实际上它的alwasys更大90)。您应该更改Low
和High
,以便r
永远不会更大59:
Sub Wait_Random()
Dim Low As Double
Dim High As Double
Dim r as Integer
Low = 1 '<<< CHANGE AS DESIRED
High = 59 '<<< CHANGE AS DESIRED
r = Int((High - Low) * Rnd() + Low)
Application.Wait Now + TimeValue("00:00:" & CStr(r))
End Sub
或者您可以使用其他方式
Application.Wait DateAdd("s", r, Now)
添加r
秒。在这种情况下,r
可能更大59
。