Michael,
You didn't include your declaration(s), but I assume:
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent
As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
I suppose you have a Kill Timer also:
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent
As Long) As Long
Not sure, but as you are not specifying a hwnd for the Timer, it has no
connection with the Excel app.
Also, did you try the code without the .Activate/.Select ? e.g.
With ThisWorkbook.Sheets("Sheet1").Range("B5").
.Value = .Value + 1
End With
However, Karl has a Timer class you may want to try:
http://vb.mvps.org/samples/project.asp?id=TimerObj
NickHK
"Michael" <(E-Mail Removed)> wrote in message
news:Od5t$(E-Mail Removed)...
> I have the following code
>
> Public TimerID1 As Long
> Public TimerSeconds1 As Single
>
> Sub StartTimer()
> ' Run the timer procedure every second
> TimerSeconds1 = 1 ' how often to "pop" the timer.
> TimerID1 = SetTimer(0&, 0&, TimerSeconds1 * 1000&, AddressOf
TimerProc1)
> End Sub
>
> Sub TimerProc1(ByVal HWnd As Long, ByVal uMsg As Long, _
> ByVal nIDEvent As Long, ByVal dwTimer As Long)
>
> Call CountUp
>
> End Sub
>
> Sub CountUp()
>
> ThisWorkbook.Sheets("Sheet1").Activate
>
> Range("B5").Select
> Selection.Value = Selection.Value + 1
>
> End Sub
>
> While the code runs if I try to bring any modal dialog (E.g. File -->
Saves
> As or attempt to refresh a PivotTable on the same workseet), Excel
crashes!
>
> What I want to do is to execute some code to kill any modal dialogs before
I
> execute the code inside the StartTime sub. Any sample code for this?
>
> Thanks in advance
> Michael
>
>