vba: passing a variable into error handles

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

    You can use Err to get the error No and Description

     Sub|Function SomeName()
         On Error GoTo Err_SomeName          ' Initialize error handling.
         ' Code to do something here.
     Exit_SomeName:                          ' Label to resume after error.
         Exit Sub|Function                   ' Exit before error handler.
     Err_SomeName:                           ' Label to jump to on error.
         MsgBox Err.Number & Err.Description ' Place error handling here.
         Resume Exit_SomeName                ' Pick up again and quit.
     End Sub|Function
    

提交回复
热议问题