PDA

View Full Version : Interrupt Handling



neeeel
10-01-2010, 03:35 PM
I am writing code for an excel sheet, which constantly polls another application for information. I am having problems being able to interrupt this.

I did a quick search and came up with this code

Public Sub Start()
On Error GoTo UserInterrupt
Application.EnableCancelKey = xlErrorHandler
For i = 1 To 10000000
For t = 1 To 10000
Next t
Next i
Exit Sub
UserInterrupt:
If Err = 18 Then
If MsgBox("Stop processing?", vbYesNo) = vbNo Then
'Keep running at the point procedure was interrupted
Resume
Else
'Handle other errors that occur
'MsgBox Error(Err )
End If
End If
End Sub
When I run this, I can interrupt it for a certain amount of time, but as soon as Excels menu bar changes to "Not Responding", Excel whites out, I cant interrupt at all and have to shut down the program and restart. Why does it only work for a certain amount of time, and how do I get round this problem?

I have the same problem when I run this code with my code which polls the application. I can interrupt it for the first few seconds, then I get "Not Responding" and when I click on the Excel sheet it whites out.

thanks for any help

Bob Phillips
10-01-2010, 04:09 PM
Is this Excel 2010?

neeeel
10-01-2010, 04:11 PM
As far as I can tell, its Excel 2007

Bob Phillips
10-01-2010, 04:13 PM
It is just that Not Responding is something I get a lot with 2010, although I can't say I have seen it with 2007.

neeeel
10-01-2010, 04:14 PM
In my program list in the start menu, it says microsoft excel 2007

Paul_Hossler
10-02-2010, 08:13 AM
Maybe the loop is too tight and Excel never gets back to Windows to see if there was a Break

See if a DoEvents makes it more reliable


For t = 1 To 10000
DoEvents
Next t


Paul