Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 出现错误时,强制函数返回_Vba - Fatal编程技术网

Vba 出现错误时,强制函数返回

Vba 出现错误时,强制函数返回,vba,Vba,我有一个返回字符串的函数 在出现错误时,我希望它返回一个特定的值。如何执行此操作?如果发生错误,请使用On Error GoTo分支到特定标签: Function YourFunction() { On Error GoTo ErrorLabel ... your code ... Exit Function ErrorLabel: YourFunction = yourspecificvalue } 如果发生错误,请使用“错误转到时的”分支到特定标签: Functio

我有一个返回字符串的函数

在出现错误时,我希望它返回一个特定的值。如何执行此操作?

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

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

如果发生错误,请使用“错误转到时的
分支到特定标签:

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