```Public Declare PtrSafe Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As LongPtr) As Long
Public Declare PtrSafe Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, _
ByVal nIDEvent As LongPtr) As Long
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public TimerID As Long
Public mymy As Integer
Sub StartTimer()
TimerID = SetTimer(0&, 0&, 50&, AddressOf TimerProc)
DoEvents
End Sub
Sub EndTimer()'触直接excel闪退
On Error Resume Next
KillTimer 0&, TimerID
End Sub
Sub TimerProc()
mymy = mymy + 1
Sheet1.Cells(5, 5) = mymy
End Sub
参考:
http://www.exceloffice.net/archives/1245
不要在vba/vb里使用带有回调函数的api(比如你这个addressof TimerProc),因为vba/vb缺乏异常处理机制,在回调中的异常会导致整个程序崩溃