'Application.OnTime throwing "Object Required" error even though I clearly put the object [closed]
I have a macro that is throwing an error when I attempt to schedule it to run itself later. I have pounded my face on the desk to the point of exhaustion, but no help.
It errors on the "Application.OnTime" line and says: Run-time error '424': Object required
Public Sub WaitForItGas()
rtime = Now + TimeValue("00:00:02")
If Range("GasDoneCheck").Value <> 1 Then
DoEvents
Applicaion.OnTime EarliestTime:=rtime, _
Procedure:="WaitForItGas", _
Schedule:=True
DoEvents
Else
MsgBox "done"
End If
End Sub
I have tried declaring the name of the procedure to schedule (in this case the name of the procedure itself), a string variable, as a public constant. I have tried setting it to schedule running another sub, which in turn runs this sub. I have tried various versions of formatting on my code. It's pretty simple code, I'm out of ideas.
Solution 1:[1]
Application is spelled wrong.
Public Sub WaitForItGas()
rtime = Now + TimeValue("00:00:02")
If Range("GasDoneCheck").Value <> 1 Then
DoEvents
Application.OnTime EarliestTime:=rtime, _
Procedure:="WaitForItGas", _
Schedule:=True
DoEvents
Else
MsgBox "done"
End If
End Sub
Addemdum
As FunThomas commented, use Option Explicit will make it easier to catch these types of errors.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
