+ Reply to Thread
Results 1 to 9 of 9

Error handling--resume next loop, but for a "DO WHILE" loop

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    Exceland
    MS-Off Ver
    Excel 2010
    Posts
    24

    Question Error handling--resume next loop, but for a "DO WHILE" loop

    Hi,

    I currently have a loop that cycles through all word files in a folder like below:

    Please Login or Register  to view this content.
    Some of these files may be broken, in which case I would like to skip the rest of that loop, and continue onto the next file. Is it possible to do error handling for such a "DO WHILE" loop? If not, any idea how I might use a more standard For Loop that can still cycle through all word files in a folder?

    Thank you!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    How are the files 'broken'?

    If you can you test if a file is broken then you can skip it and move on with the loop.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-12-2012
    Location
    Exceland
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error handling--resume next loop, but for a "DO WHILE" loop

    I just mean that something is incompatible about the file. To be more specific, I'm looking for a particular table in each word file, and some of the docs don't have this table, and would generate an error in the code. So in that case I'd like to skip to the next file. Can you do that for a "DO WHILE" loop?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    It's not the loop that you need to worry about.

    In the code within the loop you need to check if a file is compatible.

    If it is compatible continue on with the rest of the code.

    If it isn't skip the code and close the file.

    The loop will continue on.

    If you post the rest of the code perhaps I can show you what I mean.

  5. #5
    Registered User
    Join Date
    12-12-2012
    Location
    Exceland
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error handling--resume next loop, but for a "DO WHILE" loop

    What is the code for skipping the rest of the code and moving onto the next file?

    The body is mostly below:

    Please Login or Register  to view this content.
    The error occurs when the doc I open doesn't have 7 tables.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Try this.

    Unless the document has 7 tables the code will be skipped.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    12-12-2012
    Location
    Exceland
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error handling--resume next loop, but for a "DO WHILE" loop

    Is there a generic form of error handling? Something in the format of "on error goto err_handler" for a Do While loop? I think your solution will work, but for future reference I'm curious. Or is it only possible to exclude errors by using the If call before the error even takes place?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    I suppose you could try using On Error Resume Next or similar.

    One thing with that is it is triggered by any error, so you could actually be kind of hiding errors.

  9. #9
    Registered User
    Join Date
    12-12-2012
    Location
    Exceland
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: Error handling--resume next loop, but for a "DO WHILE" loop

    OK. Appreciate your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1