ontime error

G

gmferg1

The following code gives me the error "macro The_Sub cannot be found".
What is wrong? The code is enterend in the Workbook module and the
ontime does execute 10 seconds after I open the workbook. That is when
I get the error.

Public RunWhen As Double
Public RunWhat As String
Public myOffset As Double

Sub Workbook_Open()
myOffset = 0
StartTimer
End Sub

Sub Workbook_Close()
StopTimer
End Sub

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, 10)
RunWhat = "The_Sub"
Application.OnTime earliesttime:=RunWhen, procedure:=RunWhat,
schedule:=True
End Sub

Sub The_Sub()
Range("A4").Offset(0, myOffset) = myOffset
myOffset = myOffset + 1
StartTimer
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime ealiesttime:=RunWhen, procedure:=RunWhat,
schedule:=False
End Sub
 
T

Tom Ogilvy

This should all be in A general module (insert=>Module in the VBE)

Public RunWhen As Double
Public RunWhat As String
Public myOffset As Double

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, 10)
RunWhat = "The_Sub"
Application.OnTime earliesttime:=RunWhen, procedure:=RunWhat,
schedule:=True
End Sub

Sub The_Sub()
Range("A4").Offset(0, myOffset) = myOffset
myOffset = myOffset + 1
StartTimer
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime ealiesttime:=RunWhen, procedure:=RunWhat,
schedule:=False
End Sub


-------------
This should be in the ThisWorkbook module:

Sub Workbook_Open()
myOffset = 0
StartTimer
End Sub

Sub Workbook_Close()
StopTimer
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

Top