vba - VBA 中 End 语句的替代方法

标签 vba excel

我有一个调用模块的过程。像这样的东西:

程序:

Sub Procedure()

    Module1.SubProcedure()

    If Global.Variable = "A" Then
        ...
    End If

End Sub

模块1:
Sub SubProcedure()

    If x then 
        Exit Sub
    ElseIf y then
        End
    End If

End Sub

使用“结束”重置 Global.Variable。是否有任何替代“结束”的方法可以停止执行过程()并保留 Global.Variable 的值?

最佳答案

您可以使用函数而不是使用子过程,然后返回一个 bool 值,如下所示:

Function SubProcedure() as Boolean

    If x then 
        SubProcedure = false
    ElseIf y then
        SubProcedure = true
    End If

End Function

并将这些行添加到程序代码中:
if module1.subprocedure then
   End
end if

关于vba - VBA 中 End 语句的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28056458/

相关文章:

vba - Excel 和 VBA : 'If value is less than 1' condition being triggered by a value that is exactly 1

excel - 打开excel文件时如何将计算模式设置为手动?

excel - Excel Slicer 的应用程序定义或对象定义错误

c# - (不支持嵌套事务)在mysql数据库中使用excel表插入数据时

excel - 从VBA中的日期中减去?

vba - 如何使用 Outlook VBA 在电子邮件中指定光标位置和文本格式

excel - 对话框中的取消或 esc 按钮保存名为 "False"的文件

excel - 从多张纸中复制彩色单元格并粘贴到一张纸中

运行 Excel 宏的 Python

vba - 确定单元格是否通过 Excel 中的 VBA 链接到查询表