Hi, I have an Error Label inside a for next loop, and when an error is trapped the error label is called but the for next loop is not exited and becomes an endless loop... Code: Sub MySuberrorlabel (error)for x = 0 to 49D Somethingnext xerror:msgbox("file was not created!!",,cMsgBoxOK,cMsgBoxExclamation)End Sub How can I exit the loop when the error is trapped? I've tryed Exit and Return with no success!!
I tested your code and tried even a "do while" loop. Its a strange behaviour! Sometimes it seems to work fine, sometimes the application seems to hang, even on the desktop just executing a "do nothing loop" with only 40 repeats.
I think that perhaps you need to have a variable inside the For Next loop that is examined each time around the loop. If the error is caught then the variable can be set and this in turn causes the loop to be broken, personally I would use the Break command to exit the loop. Regards, RandomCoder
Thanks for your help,It seems the problem is solved...in my sub I had an open conection to a file and when the error was trapped the file wasn't closed causing the endless loop...Now it works fine