Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default API Timer Function Issue

Hi Seth,

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).


Excel isn't very fond of the API timer. It tends to get hold of Excel
at moments that Excel doesn't want it to.

E.g.: one can set the API timer to run a sub which will try to do
things to Excel, for instance save a workbook. If those actions are
actions normally not permitted in the current state (e.g. whilst in
print preview!), Excel might crash hard.

That being said, is it not possible to use the Ontime method instead?

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to have a timer or stopwatch function in Excel. JSenew Excel Worksheet Functions 3 October 23rd 07 08:36 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM
Timer function needs improvement Mike K Excel Worksheet Functions 0 July 17th 05 05:35 AM
Timer function Jan Kronsell[_3_] Excel Programming 3 October 16th 03 05:25 PM
Timer function Bob Phillips[_5_] Excel Programming 0 July 23rd 03 09:46 PM


All times are GMT +1. The time now is 08:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"