vba: passing a variable into error handles

后端 未结 4 1677
后悔当初
后悔当初 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:47

    I can't think of a clever way to do it. I normally have an error handeling class/function that way I can use "on error goto" to pass the error to the bottom block then call the error handeling function. The advantage of this is it's nice to have a centralised error handler but also you can customise it so in my case I pass the name of the procedure thats crashed. It's not pretty but you could if you really wanted to pass either a collection of variables (dependant on how many you have) or set up something to identify the variable based on the line number (which you'd have to add manauly...)

    on error goto err
    
    'Code
    
    err:
    
    ErrorHandeler err, "String with Procedure name"
    

提交回复
热议问题