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, ?
Asked
Active
Viewed 1,017 times
0
-
2Look at Application.OnTime – Tim Williams Aug 09 '16 at 05:42
-
If the Button Click Calls any Subroutine, i would suggest calling the Subroutine for every 30 secs.Further to delay have a look at this link http://stackoverflow.com/questions/1544526/how-to-pause-for-specific-amount-of-time – Siva Aug 09 '16 at 05:44
-
Yes its possible `Application.OnTime Now + TimeValue("00:00:30"), "your subroutine"` – Karthick Gunasekaran Aug 09 '16 at 05:50
2 Answers
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