每30秒按一次buttonvba
我创build了一个表单button,并为其分配了一个macros。 我希望每30秒按下一次窗体button。 这是可能的通过VBA代码,?
这是一个XY问题。 你的button调用一个例程(macros),所以直接调用该macros,而不是每隔30秒按下一次button。
您可以使用Application.OnTime
为此。 示例代码:
Sub myMacro() Dim a as Integer a = dostuff() Application.OnTime Now() + TimeValue("00:00:30"), "myMacro" 'This will cause the sub "myMacro" to execute every 30 seconds, starting when you first call it anywhere End Sub
尝试使用下面的代码
Sub mycode() MsgBox ("Hello Shajee Rehman") Application.OnTime Now() + TimeValue("00:00:30"), "mycode" End Sub