Mitch_Morgan
New Member
- Joined
- Dec 6, 2020
- Messages
- 7
- Office Version
- 365
- Platform
- Windows
I am new to VBA coding and I have read all the threads that seem to cover this but I am doing something wrong. I have built a time loop simulation that I would like to start with a command button and stop. The simulation code all resides in one module "Main". To create the loop I have the following
The last line in the last Sub I have Timer to cause it to loop. This works fine. I have inserted a form command button and assigned the macro "Timer".
The stop code is
I receive a Run-time error '1004' Method 'OnTime of object'_Application Failed
I have read this same error message occuring in other threads but the fixes I have tried do not work
VBA Code:
Sub Timer()
Dim Time_loop
Time_loop = Now() + TimeValue("00:00:01")
Application.OnTime Time_loop, "Main"
End Sub
The last line in the last Sub I have Timer to cause it to loop. This works fine. I have inserted a form command button and assigned the macro "Timer".
The stop code is
Code:
Public Sub StopTimer()
Application.OnTime Time_loop, "Timer", schedule:=False
End Sub
I receive a Run-time error '1004' Method 'OnTime of object'_Application Failed
I have read this same error message occuring in other threads but the fixes I have tried do not work