You can't run that code in the ThisWorkbook module as posted. ThisWorkbook is a class module and procedures in it aren't available outside of the class by default. First, you need to make any procedure called by OnTime public so it's accessible from outside the class (OnTime lives outside the class). Next, any references to the procedure need to be preceded by the class name. With this two changes, your code will look like this:
Public dTime As Date
Dim lNum As Long
Public Sub RunOnTime()
dTime = Now + TimeSerial(0, 0, 10)
Application.OnTime dTime, "ThisWorkbook.RunOnTime"
lNum = lNum + 1
If lNum = 3 Then
CancelOnTime
Else
MsgBox lNum
End If
End Sub
Sub CancelOnTime()
Application.OnTime dTime, "ThisWorkbook.RunOnTime", , False
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…