• Error Handling only works once

    Home » Forums » Developers, developers, developers » DevOps Lounge » Error Handling only works once

    Author
    Topic
    #2377852

    Using VBA in Word.

    In several situations I have tried to setup error handling only to find that the handler only works the first time. For example:

    Selection.MoveDown Unit:=wdParagraph, Count:=3
    On Error GoTo DONOTDELETE
    If Selection.Paragraphs(1).Range.Characters.Count < 2 Then
    Selection.Paragraphs(1).Range.Delete
    End If
    DONOTDELETE:

    In the above, I found myself in an empty table cell, so it will not delete. I setup an error handler to move past that if/then. It worked great the first time. However, when going to the next table and trying it again, I got the same error I did before I setup the error handler. How do I get the error handler to work every time?

    Viewing 0 reply threads
    Author
    Replies
    • #2378000

      It has been a long time since I programmed in Visual Basic. I think that this what you need to do…

      After you do whatever under DONOTDELETE:, you need to clear the error code by adding a line with On Error Resume Next in order to reset the error code while keeping error trapping enabled, and then you need to loop back to the top of your code (use a GoTo statement to get back to the top of your code just before the first line of your code).

    Viewing 0 reply threads
    Reply To: Error Handling only works once

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: