+ Reply to Thread
Results 1 to 4 of 4

How to run a subroutine if the main routine crashes

  1. #1
    Registered User
    Join Date
    04-10-2014
    Location
    Tallahassee, FL
    MS-Off Ver
    Excel 2010
    Posts
    98

    How to run a subroutine if the main routine crashes

    What I want to write is a piece of code that, no matter WHERE in the process the program is running, if it hits an error I haven't coded for, it runs this one subroutine.

    I was thinking I use
    Please Login or Register  to view this content.
    but that seems to be limited to requiring one in EACH subroutine, unless I am reading this incorrectly. What I am hoping for is one piece of code that rides overwatch over the whole process and, before it passes control to the user after a code break, it runs one subroutine first.

    Any ideas? Will the Application.EnableCancelKey work for that?

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260

    Re: How to run a subroutine if the main routine crashes

    Enablecancelkey only works for the user interrupting the process, not unhandled errors. The only way you can have a global error handler like that really is to pass errors back up the stack to an error handler in the main calling routine - if you have error handling in the called routines, they need to pass the error back by raising it again.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    04-10-2014
    Location
    Tallahassee, FL
    MS-Off Ver
    Excel 2010
    Posts
    98

    Re: How to run a subroutine if the main routine crashes

    Is there an event I can, perhaps, tie it to? One that happens once control is returned to the user?
    Last edited by Phixer; 10-06-2014 at 02:32 PM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,260

    Re: How to run a subroutine if the main routine crashes

    Nope - you're in break mode then and no code will run.

+ 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] Call Private Sub Routine From Main Macro
    By timbo1957 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2013, 04:50 AM
  2. Return subroutine value to main routine
    By Mark Heuckeroth in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-03-2010, 04:56 AM
  3. Excel sometimes crashes when running a sub routine
    By Brunstgnegg in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 08-20-2010, 06:55 AM
  4. Excel crashes when I create code through a routine
    By Caligula in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2007, 03:55 PM
  5. Call another subroutine when current routine ends
    By ST4RCUTTER in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2007, 07:16 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