+ Reply to Thread
Results 1 to 4 of 4

is it possible to wait and try again on error

  1. #1
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    is it possible to wait and try again on error

    I am having intermittant problems with my program failing when calling an email routine. I'm pretty sure I know where and why the error is occuring and (with help from here ) have tried a number of things to overcome the issue. It is very intermittant and may happen perhaps once out of every 10 times it is run. Basically my code copies a couple of worksheets to a new workbook, saves this then calls an email subroutine to create a new email message and attach the saved workbook.
    I'm pretty sure that what happens is that sometimes (presumably depending upon PC speed and other processes running) the workbook is still saving when the email routine tries to attach the workbook, when this happens I I don't get the usual debug error, instead I get a runtime error, Application failed from which the only option is 'Exit' which then styops my code part way through.
    I can overcome the issue by adding a wait of say 10 secs. before calling the email, however sometimes the code loops through 10-15 times so this adds considerably to the overall runtime.

    What I am thinking is can I add a wait on error, something like:

    Please Login or Register  to view this content.
    I assume I can't call the routine from within itself but I hope this illustrates he kind of solution I am thinking of.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: is it possible to wait and try again on error

    I would try to find out why there may be such a delay in saving
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: is it possible to wait and try again on error

    If you're running that code from within Excel how are you saving the workbook? I ask because AFAIK VBA would be synchronous in this instance, so the workbook must have finished saving before further code is executed.

  4. #4
    Forum Contributor tkowal's Avatar
    Join Date
    11-20-2010
    Location
    Miami, Fl
    MS-Off Ver
    Excel 2010
    Posts
    150

    Re: is it possible to wait and try again on error

    Have you tried using the DoEvents function to yield to operating system......

    Some times this works miracles on processes that take a long time ......

+ 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