API-Timer in VBA does not work in Outlook2003!

M

Michael Lorenz

Hello:)

Tryed to make a timer in VBA (Code listed at the end) But everytime I
restart my Outlook2003 after executing the right-working Timer I get a
message that the last time I closed Outlook there was an big error. Then VBA
is deactivated and I have to activate it again.
With OutlookXP at my company: it works. What to make different in
Outlook2003?

Thanks
Michael


Code:

Option Explicit

Public Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal
nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal
nIDEvent As Long) As Long

Public THdl As Long

Public Sub StartApiTimer(ByVal mSec&)
THdl = SetTimer(0&, 0&, mSec, AddressOf TimerProc)
End Sub

Public Sub TimerProc(ByVal hWnd&, ByVal uMsg&, ByVal CurTHdl&, ByVal
CurSystemTime&)
Msgbox("it works:)")
End Sub

Public Sub StopApiTimer()
KillTimer 0&, THdl: THdl = 0
End Sub
 
M

Mike Walker

Hi Michael

Without the error message and debug I am taking a guess that the timerproc
has been destroyed or is being destroyed as it is being called therefore
causing the crash, you could try and wrapper the code for errors and or the
infamous on error resume next to see if it stabilises else a catch on the
quit event of outlook maybe necessary to close the timer in a more official
fashion.

Hope this helps

Mike Walker
(Reply via NG)
 
M

Michael Lorenz

Thank you very much!!
Now it works :)

Mike Walker said:
Hi Michael

Without the error message and debug I am taking a guess that the timerproc
has been destroyed or is being destroyed as it is being called therefore
causing the crash, you could try and wrapper the code for errors and or the
infamous on error resume next to see if it stabilises else a catch on the
quit event of outlook maybe necessary to close the timer in a more official
fashion.

Hope this helps

Mike Walker
(Reply via NG)
 

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