Stopping a series of macros

D

Dave

Hi,
XL2000
I have a macro which calls a bunch of other macro's in order.

Sub DoAll()
Application.ScreenUpdating = False
Call ImportData
Call PasteRelevantImportData
Call ConcatonateComments
Call SortInitial
Call GroupDups
Call BestGuessColB
Call BestGuessColD
Call SortFinal
Application.ScreenUpdating = True
End Sub

Some of the macros contain error handling lines like:
If such-and-such Then Exit Sub.
So that particular Sub ends, and the DoALL macro calls the next Sub.
I need a line of code that will actually stop the DoAll macro, not just the
one that is executing at the time. Is this possible?

Regards - Dave.
 
T

Tim Williams

You could use a global boolean to track success of each step

Eg:

Dim bStop as boolean

Sub DoAll()
bStop=False
Call ImportData
If not bStop then Call PasteRelevantImportData
.....
End Sub

where bStop might be set in ImportData before the Exit Sub statement.

Or switch your subs to functions and test the return values.

Tim
 
H

Harald Staff

Hi Dave

You want your Sub to return a result (like successful, something like that).
Make it a function, a Sub is nothing but a function returning nothing:

Function ImportData() As Boolean
'importing, do stuff, then check
If Data.Count > 0 then 'or whatever, success, we have data:
ImportData = True
end if
End Function

And then in Doall:

Sub DoAll()
If ImportData = False Then Exit Sub
If PasteRelevantImportData = False Then Exit Sub
and so on, as needed

HTH. Best wishes Harald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top