In many cases an ‘Exit Sub’ statement will suffice when wanting to stop an agent…but if you have nested Sub Routines, the ‘Exit Sub’ might not be good enough. You see, ‘Exit Sub’ does exactly what it says…it Exits the current Sub Routine that’s in Action. This will be fine if you only have one Sub Routine, but in the event you are in a Sub Routine which is called from another Sub Routine….’Exit Sub’ will take you out the current Sub Routine you’re in, but it will continue running the initial Sub Routine.To stop an agent from running irrelevant of which Sub Routine you’re in, you’ll use the statement ‘End‘. See example below:
Sub MyRoutine1
     ‘ Call the second Sub Routine
     Call MyRoutine2
     ‘ This following Print statement will run if ‘Exit Sub’ is used in the MyRoutine2 Sub
     Print “This is a Test Message”
End Sub
Sub MyRoutine2
     ‘ If you want to exit this Sub Routine, but still want to continue running the previous Sub Routine then use the following:
     Exit Sub
     ‘ If you want to stop the entire Agent dead in its tracks, without running any further code then use the following:
End Sub