+ Reply to Thread
Results 1 to 11 of 11

Best way to handle if error with call function

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Best way to handle if error with call function

    Hi guys,

    Please see this code:
    Please Login or Register  to view this content.
    So this is verry simple code which runs several macros after eachother.
    Now it could be that one of these runs into error (ligit) because there is no data in the folder they are for.
    Then of course the macro will crash.
    But what I want is that it then just continious to the next macro.

    What would be the best and cleanest way to adjust this code to do so?
    Thanks!

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Best way to handle if error with call function

    Please Login or Register  to view this content.
    and so on

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

    Re: Best way to handle if error with call function

    Can't you handle the errors in the code of the subs being called?

    For example, check that there are files in a folder before continuing.
    If posting code please use code tags, see here.

  4. #4
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Best way to handle if error with call function

    Hmm dunno if I understand this right yudlugar.
    So it cannot be done in the macro which calls the sub-macros but has to be done in the sub-macros themself?
    Ok if so but I do not grasp which code then makes sure that when "sub Merge_CSV_DHL_OUT()" runs into error it automatically goes to number 2 in the list "Call Merge_XLS_FEDEX_OUT".

    Because I think now you want me to put everything in 1 macro?

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Best way to handle if error with call function

    Quote Originally Posted by Norie View Post
    Can't you handle the errors in the code of the subs being called?

    For example, check that there are files in a folder before continuing.
    Yes could also be option but how then to tell the macro that the next sub-macro in line should be run?

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Best way to handle if error with call function

    Please Login or Register  to view this content.
    you could do it like that I guess.

  7. #7
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Best way to handle if error with call function

    Hmm thanks Yudlugar.
    That looks likes it worth a shot, I am going to try that.

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

    Re: Best way to handle if error with call function

    rpinxt

    You don't need to, after you've dealt with the error you exit the sub.

    Then code execution will return to the calling sub, GenerateOutbound, and the next sub will be called.

  9. #9
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Best way to handle if error with call function

    Quote Originally Posted by Norie View Post
    rpinxt

    You don't need to, after you've dealt with the error you exit the sub.

    Then code execution will return to the calling sub, GenerateOutbound, and the next sub will be called.
    That would also be good.
    Thanks guys! These solutions will help me one way or the other

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Best way to handle if error with call function

    @rpinxt - that was essentially what I was looking at doing first, just with a generalised error handling in each individual sub (if there is an error to just skip to the end).

  11. #11
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Best way to handle if error with call function

    Quote Originally Posted by yudlugar View Post
    @rpinxt - that was essentially what I was looking at doing first, just with a generalised error handling in each individual sub (if there is an error to just skip to the end).
    Ah ok sorry I did not understand right away.
    But must say your second solution also looks nice.
    And I would not have to adept all the underlying macros with error handling code if I can do it on the master macro.

+ 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. [SOLVED] Getting an error when trying to call a function from a sub, with string value of cell
    By RebelScum in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-21-2012, 06:21 AM
  2. [SOLVED] Function Call on left-hand side... error
    By SeanDamnit in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2012, 07:08 AM
  3. Call a function on error
    By Niandler in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-18-2010, 04:30 PM
  4. error 28: out of stack space call function
    By ina in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-24-2006, 02:30 PM
  5. [SOLVED] MSForms UserForm Window Handle - Win32 API Call from VBA
    By Sean Connolly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-06-2005, 01:05 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