Run - time error '1004'

M

MAX

Hello,

I have a file with a code for blinking text.
At this moment I am entering some data in this file, so I click on macro in
the tool bar to stop the blink texts. The problem is that after I save the
file and come to close the file, a window appears with this error.

Run - time error '1004'
Method 'On Time' of object '_Application' failed.

Continue End Debug Help

When I click Debug, it is giving me these offending lines:

Application.OnTime RunWhen, "StartBlink1", , False
Application.OnTime RunWhen, "StartBlink2", , False
Application.OnTime RunWhen, "StartBlink3", , False
Application.OnTime RunWhen, "StartBlink4", , False

Any help please,
Thanks in advance.
 
O

OssieMac

Hi Max,

I would suggest that you have started the timer a number of times and have
not been stopping it properly.

Timer must be stopped with same variable that started it otherwise xl does
not know which "session" of the timer to stop. The following is an extract of
an example from a timer that displays the time in a text box. It has a button
to start the timer and a button to stop it.

You must stop Application.OnTime with exactly the same variable that you
started it with. Best to declare it as a Public varible in the declarations
area at the top of a standard module.

Public nextCheck As Date

'The following code re-runs the sub at intervals set by nextCheck variable
Sub RunAtIntervals()

Calculate 'Force calculation to update time

'Include code here to copy elapsed time
'to Userform TextBoxes if required.

'Set nextCheck to number of seconds
'required before next re-calculate.
nextCheck = Now + TimeSerial(0, 0, 1)

'Following line programs this sub to
'execute at the nextCheck time interval.
Application.OnTime nextCheck, _
Procedure:="RunAtIntervals"

End Sub

'The following sub stops the Ontime with a button click.
'Note it stops the timer started with NextCheck not
'one started with any other variable.

Sub StopTimer()

'Cancel OnTime.
'Returns error if previously stopped hense the On Error Resume Next.
On Error Resume Next
Application.OnTime _
EarliestTime:= nextCheck, _
Procedure:=" RunAtIntervals", _
Schedule:=False
If Err.Number > 0 Then Exit Sub
On Error GoTo 0
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Run - time error '1004' 1
Run Error while protected 1
Protection in VBA. 2
Code Error 3
Code Stopped 1
Close help 2
Help! Combine Macros 2
Run time error 2

Top