Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Error trapping a specific error (WinXP/Word2003)

    Could someone point me in the right direction for error trapping code to trap just one specific error, please? Or to be more accurate, to *not* trap one specific error - I want the code to ignore this line if it can't find what it wants, preferably template-wide.

    I can't seem to find anything in the help except the standard 'on error resume next' - it would have been nice if 'on error 380 resume next' worked, but of course it doesn't!

    Any help gratefully appreciated!
    Beryl M


  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Hi Beryl,
    Use a normal error handler and within it have:
    <code>
    If err.number = 380 then
    Resume next
    else
    do whatever
    end if</code>

    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Thanks, Rory.

    Just to check, though, if I don't put anything more there, will it stop with normal error messages for everything else? That is, if I have:

    errTrap:
    If Err.Number = 380 Then Resume Next

    at the end of the sub (and "on error goto errTrap" at the top, of course), will it ignore error 380 and behave normally for everything else? Or is there anything else I need to add?

    You can tell I'm not terribly au fait with error trapping, can't you?! <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>
    Beryl M


  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Well, looks like I can answer my own last post - sort of! I must be missing something, because it apparently completely ignores the error trap!

    <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>
    Beryl M


  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    It depends what you mean by "behave normally". It will simply resume at the next statement for error 380 but if you don't put anything else in the error handler, nothing will happen for other errors - the sub will just end.
    You could also use On Error Resume Next just before where you think there might be a 380 error and then On Error Goto 0 just after - i.e.
    <code>On Error Resume Next
    If err.number <> 380 and err.number <> 0 then do whatever 'some other error occurred
    on error goto 0</code>



    Does that help?
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Does this do what you want?

    StuartR
    <code>
    If Err.Number = 380 Then
    Resume Next
    Else
    Err.Raise Err.Number
    End If
    </code>

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Rory said:
    >Does that help?

    StuartR said:
    >Does that do what you want?

    Unfortunately, chaps, the only answer I can give is - I don't know! The error handler doesn't cut in at all!

    I put "on error goto errtrap" at the top and the errtrap: if err.number = 380 then resume next bit at the bottom, but when it hit the line that causes the error (380, as expected) it just throws up the normal error message with the end/debug/help options!

    What could be causing it to do this?! As far as I noticed there are no other error trapping bits in there ...!
    Beryl M


  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Can you post sufficient of your document that we can try to work out what is happening here?

    StuartR

    Edited by StuartR to add...
    Can you check Tools > Options > General
    look at the section called Error Trapping and make sure you don't have "Break on all errors" selected. The default is "Break on unhandled errors".

  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    Your PS looks like it was the problem - what do the two options do?
    Beryl M


  10. #10
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Error trapping a specific error (WinXP/Word2003)

    > What do the two options do.

    Here's what the help file says...
    <code>
    Error Trapping
    Determines how errors are handled in the Visual Basic development environment. Setting this option affects all instances of Visual Basic started after you change the setting.
    <UL><LI>Break on All Errors

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •