Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Windows Timer crashes Excel

I tried using Chip's Win API code at...

(Using Windows Timers)
http://www.cpearson.com/excel/ontime.htm

It ran fine, except when I was in the Edit mode. Without fail, it
shuts down Excel with no dialog box or other warning. On restart, it
shows the file as been recovered from a crash.

?? What am I doing wrong? Is there a library to reference? I couldn't
find one.

Windows 2000 5.002195 SP3
Excel 2002 SP1

TIA, and here's the code:

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

Sub StartTimer()
TimerSeconds = 5 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf
TimerProc)
End Sub

Sub EndTimer()
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Range("a1").Value = Now()
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Windows Timer crashes Excel

Excel will immediately shut down if you attempt to modify the
worksheet from within the TimerProc. I don't think there is any
way around this.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Robert" wrote in message
om...
I tried using Chip's Win API code at...

(Using Windows Timers)
http://www.cpearson.com/excel/ontime.htm

It ran fine, except when I was in the Edit mode. Without fail,

it
shuts down Excel with no dialog box or other warning. On

restart, it
shows the file as been recovered from a crash.

?? What am I doing wrong? Is there a library to reference? I

couldn't
find one.

Windows 2000 5.002195 SP3
Excel 2002 SP1

TIA, and here's the code:
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

Sub StartTimer()
TimerSeconds = 5 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf
TimerProc)
End Sub

Sub EndTimer()
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Range("a1").Value = Now()
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default Windows Timer crashes Excel

Robert,

There is a VBA ActiveX timer on my site in the Excel stuff section that
might work.

I have just tested on Excel XP, and the timer event will not fire when VB is
not in control, i.e. when you are in edit mode, which avoids the
complications you get with an unhandled API callback. It's based around the
VB timer with a wrapper around it. As an activex it is designed to go on a
form, so see the comments below.

Anyway, this is how it might be done assuming you are using Excel 2000 or
higher.

1. save your work!
2. Create a form called UserForm1
3. Add the Timer control and nothing else to the form - see my site for
instructions
4. In a module

Sub LaunchTimer()
UserForm1.Show vbmodeless
UserForm1.Hide
End Sub

In the Form code
private sub Timer1_Timer()
Beep
End Sub

Private Sub Userform_Initialize()
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub

Good luck, and let us know if it fixed the problem. I haven't had a chance
to push the control to the limits yet.

Robin Hammond
www.enhanceddatasystems.com


"Chip Pearson" wrote in message
...
Excel will immediately shut down if you attempt to modify the
worksheet from within the TimerProc. I don't think there is any
way around this.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Robert" wrote in message
om...
I tried using Chip's Win API code at...

(Using Windows Timers)
http://www.cpearson.com/excel/ontime.htm

It ran fine, except when I was in the Edit mode. Without fail,

it
shuts down Excel with no dialog box or other warning. On

restart, it
shows the file as been recovered from a crash.

?? What am I doing wrong? Is there a library to reference? I

couldn't
find one.

Windows 2000 5.002195 SP3
Excel 2002 SP1

TIA, and here's the code:
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

Sub StartTimer()
TimerSeconds = 5 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf
TimerProc)
End Sub

Sub EndTimer()
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Range("a1").Value = Now()
End Sub





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Windows Timer crashes Excel

"Chip Pearson" wrote in message ...

Thanks, Chip. I misunderstood. I now see on your sight where you warn
that will happen. Thanks for the code, though, because I can still use
it elsewhere.

-Rob

Excel will immediately shut down if you attempt to modify the
worksheet from within the TimerProc. I don't think there is any
way around this.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Robert" wrote in message
om...
I tried using Chip's Win API code at...

(Using Windows Timers)
http://www.cpearson.com/excel/ontime.htm

It ran fine, except when I was in the Edit mode. Without fail,

it
shuts down Excel with no dialog box or other warning. On

restart, it
shows the file as been recovered from a crash.

?? What am I doing wrong? Is there a library to reference? I

couldn't
find one.

Windows 2000 5.002195 SP3
Excel 2002 SP1

TIA, and here's the code:
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

Sub StartTimer()
TimerSeconds = 5 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf
TimerProc)
End Sub

Sub EndTimer()
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Range("a1").Value = Now()
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Windows Timer crashes Excel

"Robin Hammond" wrote in message ...

Thanks a bunch, Robin. I'll check it out this weekend.

-Robert

Robert,

There is a VBA ActiveX timer on my site in the Excel stuff section that
might work.

I have just tested on Excel XP, and the timer event will not fire when VB is
not in control, i.e. when you are in edit mode, which avoids the
complications you get with an unhandled API callback. It's based around the
VB timer with a wrapper around it. As an activex it is designed to go on a
form, so see the comments below.

Anyway, this is how it might be done assuming you are using Excel 2000 or
higher.

1. save your work!
2. Create a form called UserForm1
3. Add the Timer control and nothing else to the form - see my site for
instructions
4. In a module

Sub LaunchTimer()
UserForm1.Show vbmodeless
UserForm1.Hide
End Sub

In the Form code
private sub Timer1_Timer()
Beep
End Sub

Private Sub Userform_Initialize()
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub

Good luck, and let us know if it fixed the problem. I haven't had a chance
to push the control to the limits yet.

Robin Hammond
www.enhanceddatasystems.com


"Chip Pearson" wrote in message
...
Excel will immediately shut down if you attempt to modify the
worksheet from within the TimerProc. I don't think there is any
way around this.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Robert" wrote in message
om...
I tried using Chip's Win API code at...

(Using Windows Timers)
http://www.cpearson.com/excel/ontime.htm

It ran fine, except when I was in the Edit mode. Without fail,

it
shuts down Excel with no dialog box or other warning. On

restart, it
shows the file as been recovered from a crash.

?? What am I doing wrong? Is there a library to reference? I

couldn't
find one.

Windows 2000 5.002195 SP3
Excel 2002 SP1

TIA, and here's the code:
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

Sub StartTimer()
TimerSeconds = 5 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf
TimerProc)
End Sub

Sub EndTimer()
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Range("a1").Value = Now()
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Windows Timer crashes Excel

Hi Robert,

you can use 'my solution' ... a TimerControl for Office (freeware).

http://rtsoftwaredevelopment.de/Free...merControl.htm

--
Thomas

http://rtsoftwaredevelopment.de
"Chip Pearson" schrieb im Newsbeitrag
...
Excel will immediately shut down if you attempt to modify the
worksheet from within the TimerProc. I don't think there is any
way around this.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Robert" wrote in message
om...
I tried using Chip's Win API code at...

(Using Windows Timers)
http://www.cpearson.com/excel/ontime.htm

It ran fine, except when I was in the Edit mode. Without fail,

it
shuts down Excel with no dialog box or other warning. On

restart, it
shows the file as been recovered from a crash.

?? What am I doing wrong? Is there a library to reference? I

couldn't
find one.

Windows 2000 5.002195 SP3
Excel 2002 SP1

TIA, and here's the code:
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

Sub StartTimer()
TimerSeconds = 5 ' how often to "pop" the timer.
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf
TimerProc)
End Sub

Sub EndTimer()
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)
'
' The procedure is called by Windows. Put your
' timer-related code here.
'
Range("a1").Value = Now()
End Sub





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
Timer in Excel Gil Excel Discussion (Misc queries) 2 January 14th 10 12:57 PM
i want all windows in one excel frame (windows in taskbar) Subramanya Excel Discussion (Misc queries) 1 December 18th 09 03:14 PM
Windows Explorer hangs then crashes. DougJD Excel Discussion (Misc queries) 4 March 24th 09 08:58 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM
Excel VBA - Timer Xing Zhou Excel Programming 4 July 23rd 04 04:03 PM


All times are GMT +1. The time now is 11:28 PM.

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"