Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have:
Sub A Call Sub B End Sub A Sub B On Error Goto ErrH exit sub ErrH: ..... end Sub B The exit sub seems to exit out of Sub A too. Why is that? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It exits the sub or macro - stops the macro from running
"J@Y" wrote: I have: Sub A Call Sub B End Sub A Sub B On Error Goto ErrH exit sub ErrH: .... end Sub B The exit sub seems to exit out of Sub A too. Why is that? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The reason it exits sub A is that there is no following code in A :
The exit sub in Sub B returns control to A. The next line of code in A is End Sub, therefore all processing stops. The exit sub only ends that sub routine, but if there is no code in the sub above, it "flows" to the end of the routine. Try modifying the sub a by adding a line like debug.print "Now in Sub A" after the call sub B. You should see the output in the immediate window of your VB environment, or at least that line should be highlighted in your debug routine if you are using single steps (F8) to process the routine. Hope that helps MjM "J@Y" wrote: I have: Sub A Call Sub B End Sub A Sub B On Error Goto ErrH exit sub ErrH: .... end Sub B The exit sub seems to exit out of Sub A too. Why is that? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Note the two statements I added to your example that are encased in triple
asterisks... Sub B On Error Goto ErrH ***Executing Code*** exit sub ErrH: ***Line 1 Of The Error Handler Code*** .... end Sub B Just so you understand why the Exit Sub statement is in this piece of code... what it does is prevent the main body's code from entering the error handler code below it. If you did not have the Exit Sub statement, then the Executing Code, when finished, would continue with Line 1 Of The Error Handler Code... the Exit Sub stops the Executing Code from continuing on into the code marked by the label ErrH: and simply ends the execution of the subroutine. That way, the error handler code will only be executed when an error occurs. Rick |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Exit Sub | Excel Discussion (Misc queries) | |||
End and Exit Sub | Excel Programming | |||
Run when exit | Excel Worksheet Functions | |||
how to exit sub | Excel Programming | |||
If a called sub exit, how to the caller exit right away? | Excel Programming |