• Error Trap Doesn’t (Excel 2000)

    Author
    Topic
    #428595

    The error trap in one of my macros was not working but I could see nothing wrong with it, so I created a small macro to test the basic trap and it did not work – but it works fine on another computer. Both computers are using the same version (SP-3) of Excel.
    Here’s the test macro:
    Sub xxx()

    On Error GoTo BugCheck
    Windows(“xfhxfh.xls”).Activate
    GoTo AllsWell

    BugCheck:

    MsgBox (“There’s no such file.”)

    AllsWell:
    On Error GoTo 0

    End Sub

    Any thoughts?

    Viewing 1 reply thread
    Author
    Replies
    • #996077

      I see nothing wrong with it. What is not working about it exactly?

      Steve

      • #996091

        Steve,
        I get the error message “Out of range” In other words, it can’t find the file – which of course it’s not supposed to find.
        Yes, the code looks fine and works fine, but not on my computer!

        • #996093

          Does it act this way in all workbooks or only in this one?

          Steve

    • #996255

      In the VBE, check Tools, Options, General tab. Make sure you have not set “Break on All Errors”, but “Break on unhandled Errors”.

      BTW: you have not created a proper error handler. A proper error handler needs to come as the last statements in a sub or function and *has* to have a Resume Statement:

      Sub Foo()
      On Error GoTo LocErr
      MsgBox 1 / 0
      TidyUp:
      Exit Sub
      LocErr:
      MsgBox "Error!!!" & vbNewLine & Err.Description
      Resume TidyUp
      End Sub
      • #996369

        Jan,
        I’m not sitting at the affected computer at the moment, but I’m sure you’re absolutely right about the setting.
        Thank you also for pointing out the sloppy error handling. Your advice is much appreciated.

      • #996505

        Hi Jan Karel,

        Without pirating the thread, could you tell me if vbNewLine is the same as vbCrLf? The help files says: Platform-specific new line character; whichever is appropriate for current platform. What does this mean exactly?
        Tx

        • #996513

          To answer for Jan Karel who is not online at the moment: vbCrLf = Chr(13) & Chr(10) is used in most MS-DOS/Windows applications to start a new line. On some other systems, such as Apple Macintosh, vbCr = Chr(13) is used to start a new line. The symbolic constant vbNewLine will be resolved to the value appropriate for the operating system: it equals vbCrLf on Windows, and vbCr on Macintosh. So if you need code to run on both platforms, use vbNewLine.

          • #996624

            Wow…interesting. In retrospect, this may be better to use then for two reasons:
            1. Its more flexible to run over different platforms
            2. Its easier to remember and type than vbCrLf which is very abbreviated…esp. understandable for novices in code!

            Tx for the advice

    Viewing 1 reply thread
    Reply To: Error Trap Doesn’t (Excel 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: