0

I have created a form button and a macro is assigned to it. I want that form button to be pressed every 30 seconds. Is that possible via vba code, ?

2 Answers2

2

This is a X-Y problem. Your button calls a routine (macro), so call that macro directly instead of having to press the button every 30 seconds.

You can use Application.OnTime for this. Example code:

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
Magisch
  • 7,312
  • 9
  • 36
  • 52
1

Try with below code

Sub mycode()
    MsgBox ("Hello Shajee Rehman")
    Application.OnTime Now() + TimeValue("00:00:30"), "mycode"
End Sub
Karthick Gunasekaran
  • 2,697
  • 1
  • 15
  • 25