+ Reply to Thread
Results 1 to 8 of 8

How to use On Error Resume Next in VBA?

  1. #1
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    How to use On Error Resume Next in VBA?

    Hello,

    Where Exactly I should use the " On Error Resume Next" feature. if there is any error in downloading files in Case1, Case2 and Case3?


    Please Login or Register  to view this content.
    Thank you
    Last edited by zaska; 09-23-2021 at 09:33 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to use On Error Resume Next in VBA?

    On Error Resume Next should be used very sparingly. It says to ignore an error if it occurs. Usually you want to know if an error occurs, and take some alternative action. It is rare that an error could occur but doesn't have any ill effects on what you do next.

    It appears that the place where you are anticipating an error is the call to URLDownloadToFile. It further appears that if this call fails, it returns a value of 0 rather than raising an error. So where are you thinking you need On Error Resume Next?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to use On Error Resume Next in VBA?

    By the way, although your code is not wrong, it's a bit of a roundabout way to do it. I would suggest this:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to use On Error Resume Next in VBA?

    Thanks for the response

    I download three files daily i.e File-1, File-2 & File-3. Some times one or more files may not be available till the next day. For example If today File-2 is not available for download then the code downloads only File-1 and is skipping File-2 & File-3. In that case I want to resume next and download File-3.

    If File-1 itself is not available ,but File-2 and File-3 available then the code doesn't download anything.

    I am confused about the logic here where to use " On Error Resume Next", so that I could download the remaining files and skip the non available files

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to use On Error Resume Next in VBA?

    You should not need On Error Resume Next. Your code will not raise an error. It already detects a return value of 0 from URLDownloadToFile if an error occurs.

    If you find that this call is raising an error when the file is not present (which I believe it should not) then you can try this. But don't do it unless you confirm that you are getting errors.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to use On Error Resume Next in VBA?

    If you find that this call is raising an error when the file is not present (which I believe it should not) then you can try this.

    You are right , On Error Resume Next is not required. Is there any alternative so download the remaining files if any of the files doesn't exist?

    Thank you

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to use On Error Resume Next in VBA?

    I see. I misread your code. I can't figure out what your code is doing without seeing all of it. But if you remove
    Please Login or Register  to view this content.
    then the code will continue and attempt to download all files even if one fails. But you seem to have some kind of error processing going on that isn't shown.

    I suggest you post the entire module, not just part of a sub.

  8. #8
    Forum Contributor
    Join Date
    06-20-2012
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    359

    Re: How to use On Error Resume Next in VBA?

    Thank you So much. Removing Exit sub solved the issue.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 07-06-2020, 10:12 AM
  2. Runtime Error 53 On error resume next not working
    By KevBotes in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-01-2016, 11:07 AM
  3. [SOLVED] VBA help needed to capture Error and Remove Pivot if error exist else resume
    By Tescatlipoca in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2014, 05:46 PM
  4. On Error Resume Next
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2013, 11:56 AM
  5. Error pops up on line On Error Resume Next
    By Erusso in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-20-2012, 04:57 PM
  6. On Error Resume Next
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-20-2010, 10:35 AM
  7. [SOLVED] On Error {...} Resume Next
    By Edd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2006, 07:15 PM

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