View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
seth seth is offline
external usenet poster
 
Posts: 5
Default API Timer Function Issue

I am using the API timer functions in an Excel XP
project. I use the timer to refresh information every 1
second on a userform. When the user form initializes I
start the timer, and on terminate I stop the timer.

The problem is that when I return to Excel I am not able
to use the mouse to click on cells or toolbar buttons. I
found that hitting ctrl-O to open the File Open dialog
will "wake" Excel up (I can select cells and click
toolbar buttons again once I close this dialog).

Does anybody know what is going on? I only get this
problem when I use the API timer functions in conjunction
with a UserForm.

Code is shown below

Thanks,

Seth


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 TimerID As Long
Public TimerSeconds As Single

Private x As Integer

Sub StartTimer()
' I call this routine from a userform Initialize event
TimerSeconds = 1 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&,
AddressOf TimerProc)
Debug.Print "Started API timer, ID# " & TimerID
End Sub

Sub EndTimer()
' I call this procedure from a userform Terminate event
On Error Resume Next
KillTimer 0&, TimerID
End Sub

Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)

' My code here
' It all works fine
' I run the EndTimer code on the Terminate event of a
userform
' When i do this, i can't click on anything in Excel (see
problem described above)

End Sub