出错,强制函数返回

时间:2010-05-26 19:33:14

标签: vba

我有一个返回字符串
的函数 出错,我希望它返回一个特定的值。我该怎么做?

1 个答案:

答案 0 :(得分:6)

如果发生错误,请使用On Error GoTo分支到特定标签:

Function YourFunction() {
  On Error GoTo ErrorLabel
  ... your code ...
  Exit Function
  ErrorLabel:
    YourFunction = yourspecificvalue
}