View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Stop Multiple Macros

End is a really bad idea. It clears all global varaibles and stops ALL
execution. My recommendation is to turn your subs into functions that return
boolean flags indicating if the executions should continue or not. Something
like this (Change the 1 = 1 and 1 = 2 to see what happens)...

Public Sub MainProcedure()
If A = True Then
MsgBox "A Worked"
If B = True Then
MsgBox "B worked"
Else
MsgBox "B Failed"
End If
Else
MsgBox "A Failed"
End If
End Sub

Public Function A() As Boolean
If 1 = 2 Then
A = True
MsgBox "All is well with A"
Else
A = False
End If

End Function

Public Function B() As Boolean
If 1 = 1 Then
B = True
MsgBox "All is well with B"
Else
B = False
End If
End Function
--
HTH...

Jim Thomlinson


"VBA_Newbie79" wrote:

I currently have multiple macros that run in a hierarchal manner. The first
one calls the second macro, which calls the third macro, etc. There are
certain If statements in each macro that should end that macro and all macros
running before it.

Using Exit Sub with the If statement only ends the macro that the If
statement is located in. The previous macros then pick up where they left
off. I need a statement that will communicate to all running macros that if
"this" is true in this macro then end all running macros.

I investigated VBA help and came up with using End in the place of Exit Sub,
but it apparently closes all opened files and I don't want that to happen.

Any advice for a newbie?