+ Reply to Thread
Results 1 to 14 of 14

Workbook_Open ignores On Error GoTo. How to fix this?

  1. #1
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Workbook_Open ignores On Error GoTo. How to fix this?

    Try this:

    Please Login or Register  to view this content.
    Now run this in the developer window.

    The message box pops up as you would expect.

    Now move the sub to ThisWorkbook and change its name to Workbook_Open ... The sub now behaves as if On Error GoTo HandleErr just plain wasn't there. Indeed, all on error goto <handler_name> statements in every function in the stack are ignored when ThisWorkbook.Workbook_Open is called.

    What the heck??
    Last edited by XmisterIS; 03-26-2014 at 04:43 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,450

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    The first End Sub should be Exit Sub otherwise the label is outside the procedure

    Please Login or Register  to view this content.
    Other than that, it works just fine.
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    ah! Yes, sorry, that was an entirely innocent typo on my part when I was typing the code in the original message (corrected now). I still observe the behaviour I originally described in Workbook_Open, even with the file you have provided.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,450

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Maybe you need to check your security settings and that you enable macros when you open the workbook.

    The code works just fine. I copied your coded, edited the typo and put it in that workbook. Saved it, closed it and re-opened it. Displays message.


    Regards, TMS

  5. #5
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Thanks, I will check, although I do believe I have macros enabled. At least we have ruled out VBA as the source of the problem.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,450

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    You're welcome. Thanks for the rep.

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    I think perhaps you have 'Break on all errors' set in your VB Editor options?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  8. #8
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Just checked that; I have "break on unhandled errors" set.

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Do you open the workbook with code or within Excel?

  10. #10
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    What do you mean?

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    I mean do you open this workbook using Workbooks.open in vba or manually File - Open?

  12. #12
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Oic ... I open it manually.

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Is it same if you open Excel in Safe Mode and then open workbook TMS provided?

  14. #14
    Registered User
    Join Date
    08-01-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    76

    Re: Workbook_Open ignores On Error GoTo. How to fix this?

    Now here's a funny thing ... my laptop did an automatic update upon shutdown yesterday, and when I spark it up this morning ... bingo! Everything works fine (i.e. the problem is no longer there). So it was fixed by a windows update. Possibly something in excel got corrupted. Who knows!

+ 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] Finding average that ignores error and zeros
    By Elainefish in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-18-2013, 06:25 AM
  2. Replies: 2
    Last Post: 07-11-2012, 08:58 AM
  3. [SOLVED] Range.Select error and screen maximizing error in Workbook_Open()
    By Punsterr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-10-2006, 05:20 PM
  4. [SOLVED] Range.Select error and screen maximizing error in Workbook_Open()
    By Punsterr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2006, 03:00 PM
  5. [SOLVED] Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 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