Monday, 3 December 2012

VBA Excel - Stop Macro execution .

Terminating the run in your function can be done by using the keyword - "End"


Sub MySub()
    Dim x
   
    x = MyFunc("Test")
   
    MsgBox x
   
End Sub
Function MyFunc(Arg1) As Long
    If Arg1 = "Test" Then
        End
    Else
        MyFunc = 1
    End If   
End Function

Recommendation :
But using End in this way seems completely wrong. Terminating the run in your function is the wrong way.
You should pass back information via the function(s) and deal with termination in a more appropriate location.

No comments:

Post a Comment