vba: passing a variable into error handles

后端 未结 4 1637
后悔当初
后悔当初 2021-01-25 13:22

i have a statement:

on error go to label

however i would like to pass into the label the variable which caused the error

is this possib

4条回答
  •  盖世英雄少女心
    2021-01-25 13:49

    First, I think you mean:

    on error goto label
    

    And no, you can't pass variables using a goto command. However, you can check the Err.Description for details, and if you are raising your own errors, you can do this:

      ' Raise a custom error.
        Err.Raise Number:=vbObjectError + 1000, _
            Source:="TestRaiseCustomError", _
            Description:="My custom error description."
    

    So if you are raising your own error, you could set Source to the field that caused the problem.

    Refer to the Use the Err Object's Raise Method to Raise Custom Errors section at this link for more info.

提交回复
热议问题