+ Reply to Thread
Results 1 to 5 of 5

What would cause the error handler to not work?

  1. #1
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    What would cause the error handler to not work?

    My code opens a user-selected workbook and attempts to select the worksheet name that matches the current sheet in the original workbook. For some reason, the error handler doesn't get triggered if it doesn't find a matching sheet. I have copied the code to a new workbook, and it works fine there. Does anyone have ideas on what might nullify the error handler? In the code below, the FindSheetFailed is the one that won't work. Instead it gets a Subscript Out Of Range error if it doesn't find the sheet.
    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: What would cause the error handler to not work?

    Hello natefarm,

    When testing objects it is a good practice to assign the object to an object variable first rather than select it straight away. This method allows you check if the object was set and prevent the system from overriding your error handler. The changes are in bold text.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: What would cause the error handler to not work?

    Thanks for the suggestion. Unfortunately, it didn't help. I still get Subscript Out Of Range.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: What would cause the error handler to not work?

    Hello natefarm,

    To troubleshoot this further, I would need to see the workbook. Can you post a copy of it?

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: What would cause the error handler to not work?

    You won't need any:
    And you'd better avoid activate and select in VBA.

    Please Login or Register  to view this content.



+ 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