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



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


End Sub


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


Peter T

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

ThisWorkbook.Name & "!Module1.myMacro"

Peter T

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