gpt4 book ai didi

vba - VBA 出错时如何从函数返回

转载 作者:行者123 更新时间:2023-12-03 01:30:42 25 4
gpt4 key购买 nike

我是 VBA 新手,希望在看到错误时从函数返回。无法这样做。有什么指点吗?

Function GetEditboxValue(control As IRibbonControl, text As String) As String

If Not IsMissing(text) Then
If Not IsNumeric(text) Then
MsgBox "Please enter numeric value only."
' I WANT TO RETURN HERE
End If
End If


If control.id = "xyz" Then
spaceAboveTable = text
End If


End Function

最佳答案

您需要将 EXIT FUNCTION 放在那里以退出进一步执行:

Function GetEditboxValue(control As IRibbonControl, text As String) As String

If Not IsMissing(text) Then
If Not IsNumeric(text) Then
MsgBox "Please enter numeric value only."
EXIT FUNCTION
End If
End If


If control.id = "xyz" Then
spaceAboveTable = text
End If


End Function

关于vba - VBA 出错时如何从函数返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4553814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com