Ответ 1
Изменить после комментария: Просто используйте end
, где вы хотите завершить ВСЕ код.
Sub mainMethod()
method_A()
end Sub
Sub method-A()
if (true) Then End
'Terminate the macro. that is exit method-A() and also mainMethod()
end Sub
Исходный ответ: все, что вам нужно сделать, это сделать функцию methodA функцией и вернуть эту функцию как FALSE, если вы хотите выйти из основного метода в соответствии со следующим кодом:
Sub mainMethod()
'Run the custom function and if it returns false exit the main method
If Not method_A Then Exit Sub
'If method_A returns TRUE then the code keeps going
MsgBox "Method_A was TRUE!"
End Sub
Function method_A() As Boolean
Dim bSomeBool As Boolean
'Code does stuff
bSomeBool = True
'Check your condition
If bSomeBool Then
'Set this function as false and exit
method_A = False
Exit Function
End If
'If bSomeBool = False then keep going
End Function