On Error Retry
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site on error retry vba About Us Learn more about Stack Overflow the company Business Learn more about vba on error hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss on error resume next Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Retry on Runtime Errors up vote 2 down vote favorite I have come across this problem a few times and never been able to resolve it but now I need to solve it once and for all. I have a procedure which has been throwing runtime errors. This is not a problem as I have an error handler defined at the top of the function and the handler at the bottom something like this: retryConcat: On Local Error GoTo concatErr 'Some Code here Exit Sub concatErr: If MsgBox("Could not append the receipt for this transaction to the Receipt viewer logs.", vbExclamation + vbRetryCancel, "Warning - Missing Receipt") = vbRetry Then err.Clear GoTo retryConcat End If The error handler contains a message box allowing the user to retry if required. Now here is the part which confuses me. The first time an error is thrown it shows the message box and allows the user to retry as expected. The program then jumps to the appropriate line and tries again. However the second time through when the error is thrown it does not jump to the error handler, it jumps out of the procedure and the error handler in the parent catches it instead! So my question is why does it jump to the parent error handler on subsequent throws. This happens in many places all over my code. In many cases where I can manually check for errors I can stick the code in a while loop to solve it but with runtime errors I am forced to use the error
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a http://stackoverflow.com/questions/12603698/retry-on-runtime-errors community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up On Error Goto: Multiple times up vote 1 down vote favorite 1 I'm using a macro to get infos from a website: Sub get_prices() Dim IE As Object Dim URL As String Dim cell http://stackoverflow.com/questions/20957649/on-error-goto-multiple-times As Range Dim rng As Range Set rng = Range("A2", Range("A1048576").End(xlUp)) Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True For Each cell In rng.Cells comeco: On Error GoTo pau: URL = Cells(1, 2) & cell.Text & "?utm_source=teste" & Rnd IE.Navigate (URL) Do DoEvents Loop Until IE.READYSTATE = 4 Application.Wait (Now + TimeValue("00:00:05")) Cells(cell.Row, 2) = Mid(IE.Document.GetElementById("ctl00_Conteudo_ctl01_precoPorValue").innertext, 3) Cells(cell.Row, 2).Formula = _ WorksheetFunction.Substitute(WorksheetFunction.Substitute(Cells(cell.Row, 2), ".", ""), ",", ".") Next pau: IE.Quit Set IE = Nothing Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True GoTo comeco: End Sub The problem is that from time to time, my Excel kind of "loses the IE object", and I get the error message "THE OBJECT IS REQUERIED" in the following line: Cells(cell.Row, 2) = Mid(IE.Document.GetElementById("ctl00_Conteudo_ctl01_precoPorValue").innertext, 3) Normally, I just debug the code, and make a new line, like: Set IE = CreateObject("InternetExplorer.Application") and then I resume the macro. Bud I'd like to make something more robust, something that everytime an error occurs, it closes the