Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I try to find ways on how to set vba code that when anyone or more than one of subroutines has prompted "Exit Sub" will exit the main sub program E.g Sub main() ..... ..... ..... Call abc End Sub Sub abc() ..... ..... Exit Sub ....... End Sub Sub def() ..... ..... Exit Sub ....... End Sub Any helps will be appreciated and thanks in advance Regards Len |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() You need to return from the lower level sub's an error parameter. Yo ucan either turn these subs into function or return and error parameter as a byref variable in the parameter list sub Main() Error = Funct1() if Error then exit sub end if end sub function Funct1() Funct1 = True end function or ------------------------------------------ sub Main() Call Funct1(MyError) if MyError then exit sub end if end sub sub Funct1(MyError) MyError = True end function -- joel ------------------------------------------------------------------------ joel's Profile: 229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=190457 http://www.thecodecage.com/forumz |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is one way raising an error
Sub main() On Error GoTo Exit_Main Call abc Exit_Main: 'add any tear-down code Exit Sub Exit_Error: If Err.Number = 99999 Then Resume Exit_Main MsgBox Err.Description Resume Exit_Main End Sub Sub abc() 'do more stuff If Time = TimeValue("12:00:00") Then Err.Raise 9999 MsgBox "Earlier than 12" Call def End Sub Sub def() 'do stuff If Time = TimeValue("11:00:00") Then Err.Raise 9999 MsgBox "Earlier than 11" End Sub -- HTH Bob "Len" wrote in message ... Hi, I try to find ways on how to set vba code that when anyone or more than one of subroutines has prompted "Exit Sub" will exit the main sub program E.g Sub main() .... .... .... Call abc End Sub Sub abc() .... .... Exit Sub ...... End Sub Sub def() .... .... Exit Sub ...... End Sub Any helps will be appreciated and thanks in advance Regards Len |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I like to use a variable named StopCode. Before your main sub starts, by
default it is False, but set it to True just before you exit the sub or whenever you like. You can declare the variable at the top of the module if all of these subs are in one module. If they are in multiple modules you will have to declare StopCode as a Public variable. Hope this helps! If so, click "YES" below. For example, Dim StopCode As Boolean Sub main() ...... ...... ...... Call abc If StopCode = True Then Exit Sub ...... ...... Call def If StopCode = True Then Exit Sub ...... ...... End Sub Sub abc() ...... ...... StopCode = True Exit Sub ........ End Sub Sub def() ...... ...... StopCode = True Exit Sub ........ End Sub -- Cheers, Ryan "Len" wrote: Hi, I try to find ways on how to set vba code that when anyone or more than one of subroutines has prompted "Exit Sub" will exit the main sub program E.g Sub main() ..... ..... ..... Call abc End Sub Sub abc() ..... ..... Exit Sub ....... End Sub Sub def() ..... ..... Exit Sub ....... End Sub Any helps will be appreciated and thanks in advance Regards Len . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just put 'End' before 'Exit Sub'.
If all you want is to stop the main procedure from running when a specific condition is met and the 'Exit Sub' happens, then you can just put 'End' before every 'Exit Sub' and it will terminate all running subs. e.g.: Sub Main() Call abc Call def End Sub Sub abc() ... End ' <- this 'End' stops every currently running sub (including Main) Exit sub End sub Sub def() ... End ' <- this 'End' stops every currently running sub (including Main) Exit sub End sub |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't know if I would recommend using End. Because using End will clear
any Public variables values, or close any userforms that he may want to remain open. I would recommend using End if you want "absolutely everything" to stop. -- Cheers, Ryan "AB" wrote: Just put 'End' before 'Exit Sub'. If all you want is to stop the main procedure from running when a specific condition is met and the 'Exit Sub' happens, then you can just put 'End' before every 'Exit Sub' and it will terminate all running subs. e.g.: Sub Main() Call abc Call def End Sub Sub abc() ... End ' <- this 'End' stops every currently running sub (including Main) Exit sub End sub Sub def() ... End ' <- this 'End' stops every currently running sub (including Main) Exit sub End sub . |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi All,
Sorry for delay in replying my post as I was away in the weekend Thanks for your great helps and your suggestions I will try it out Regards Len |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Main Sheet | Excel Programming | |||
Exit Field vs Exit Button...... | Excel Programming | |||
Main first | Excel Programming | |||
Main menu is missing | Excel Discussion (Misc queries) | |||
If a called sub exit, how to the caller exit right away? | Excel Programming |