我已写下VBA代码,每5秒后执行一次,但它不起作用。
Option Explicit
Public RunWhen As Double
Public Const cRunIntervalSeconds = 5 ' two minutes
Public Const cRunWhat = "TheSub" ' the name of the procedure to run
Sub StartTimer()
RunWhen = Now + TimeValue(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
Schedule:=True
End Sub
Sub TheSub()
''''''''''''''''''''''''
' Your code here
''''''''''''''''''''''''
MsgBox "hi this is working"
StartTimer ' Reschedule the procedure
End Sub
我在这里失踪的是什么?
同样简单的表达式也不起作用
Sub test()
Application.ontime (now() + TimeValue("0:0:5")),"test"
End Sub
答案 0 :(得分:2)
您应该使用TimeSerial功能,而不是TimeValue。
set.seed(5)
x <- rnorm(1e6)
microbenchmark(pmax(x, 0), pmaxC(x, 0))
Unit: milliseconds
expr min lq mean median uq max neval cld
pmax(x, 0) 8.500419 8.621341 11.09672 10.132045 10.791020 58.44972 100 a
pmaxC(x, 0) 5.624480 5.709262 8.83968 7.598093 7.907853 53.91339 100 a
这很有效,您可以观看VBE的立即窗口,看看它是否已经通过。