+ Reply to Thread
Results 1 to 3 of 3

Error Handling

  1. #1
    Registered User
    Join Date
    07-19-2011
    Location
    Derby
    MS-Off Ver
    Excel 2003
    Posts
    41

    Error Handling

    Hi all,

    Ive recorded some code but im struggling with the error handler.

    Basicly I have some code which is in a do - loop. Its quite a lot of code so no point putting it all in as it wouldn’t mean anything to any one.

    Here is the starting code.

    Please Login or Register  to view this content.
    Basicly it opens up a hyperlink and copies the content from within it and then closes it again. It keeps doing this until it gets to the bottom of the list.

    My problem is that if the hyperlink that it trys to follow doesnt exsist it ends my Macro.

    what ive tryed to do is insert a error handler at the point where it follows the hyperlink to say "If there is a error when opening move down 1 cell.

    My issue is this..."

    My error handler says this

    Please Login or Register  to view this content.
    But then my code ends and it doesnt carry on with the loop it just ends my code.

    What i would like to happen is that when there is a error when trying to follow the hyperlink it just restarts just before the "Do" comment. This would move it down to the next line and carry on. Ive tried using the ON ERROR GO TO statement but that doesnt seem to work.

    The other issue is when the code finishes runing it will still pass through the error handler which will sent it back up to the DO comment and create a loop??

    Can anyone help??

    UPDATE......

    I put the error handler above the DO which did work but it will only work once. If the Hyperlink does not exist it will start before the DO comment but then if it has anouther Hyperlink that doesnt work it says cannot find file. Its as if it can only do 1 error :/
    Last edited by Sanecrazy; 06-27-2012 at 04:37 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Error Handling

    Maybe try an approach like this

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Error Handling

    Difficult to be certain without seeing the problem in the context of its workbook.

    However what's the complete On Error Goto statement line?
    Have you tried On Error Resume Next?

    To prevent the error handler code running when the loop has finished you should always put an 'Exit Sub' line before the error handler.

    Incidentally it's generally regarded as bad practice to use .Selects and .Activates since these slow down code. Most of the time these are not necessary and you can avoid them by referring directly to the object (Sheet, Range etc.).

    If none of this helps upload the workbook.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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