View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Run - time error '1004'

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, _
Procedu="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, _
Procedu=" RunAtIntervals", _
Schedule:=False
If Err.Number 0 Then Exit Sub
On Error GoTo 0
End Sub



--
Regards,

OssieMac