18

method-A()複数のメソッドから呼び出されるがありますが、

メソッドAの条件で、マクロを終了する必要があります。

私は1つのオプションを見ましExit subたが、これは現在のプログラムを終了しsub ie:method-A()、残りのプログラムは続行されます。

これを処理する方法。

Sub mainMethod()
    method-A()
end Sub

Sub method-A()
    if (true) Then
         'Terminate the macro. that is exit method-A() and also mainMethod()
end Sub
4

1 に答える 1

21

コメント後に編集: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
于 2013-02-12T07:53:06.717 に答える