OnTimer - The macro 'macro name' cannot be found.

  • Thread starter Thread starter louieuow
  • Start date Start date
L

louieuow

I am trying to use the OnTimer event to run a macro every 60 seconds while a
workbook is open.

I found lots of examples on the net and the example below on this site.

Regardless of which example I use I always get this error message when the
OnTimer event is triggered

The macro 'macro name' cannot be found.

I have tried this on several Computers - Staff machines, student lab
machines, admin assistant machines, and they all produce the same error
message each time, and the Macro Security level is set to the Not recomended
Low setting, so I know its not a fault with my PC.

We use Office 2003 with SP 3

I am writing a templating system/procedure for excel to allow Lecturers to
produce student excel template lab exercises that will reduce the temptation
for students to cheat ( cut/paste other people work, submit another's
workbook etc). The ontimer event is ment to show the lab demostrators in real
time how long the student has been working on the exercise, was they walk
around the lab.

//------------------------------------------
Private mNextTime As Double
Private mCounter As Long ' for test routine

Sub OnTimer()
mNextTime = Now + (TimeSerial(0, 0, 1))
Application.OnTime mNextTime, "myMacro"
End Sub

Sub StopTimer()
' call StopTimer in the workbook's close event or antime to stop the OnTime

If mNextTime Then Application.OnTime mNextTime, "myMacro", Schedule:=False
mNextTime = 0

End Sub

Sub myMacro()

''' do stuff
mCounter = mCounter + 1
Cells(mCounter, 1) = Format(mNextTime, "hh:mm:ss")
''' do stuff done

OnTimer

End Sub
 
hi
i just tested your code on xl03. worked perfectly.
where do you have the MyMacro macro?

regards
FSt1
 
Is all your code in the same module as the module level variables declared
as Private

Are you sure another macro named "myMacro" does not exist in the same
project or even in any other open project.

Try fully qualifying, change in the OnTime calls

"myMacro"
to
ThisWorkbook.Name & "!Module1.myMacro"

Regards,
Peter T
 
Back
Top