Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Flag me if macro errors

I have series of 6 macros I call with a master macro. I'd like all macros to
run. If 1 or more macros errors out, I'd like it to move to the next macro in
the sequence, then notify me at the end (with a msgbox) which macros errored
out. Here's the basic construct. Thx.

Sub mMasterMacro()

On Error GoTo Exit_Me
Application.ScreenUpdating = False

'Run macros
mMacro1
mMacro2
mMacro3
mMacro4
mMacro5
mMacro6

Exit_Me:
Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Flag me if macro errors

Jason,

Make them functions that return a Boolean, and trap errors and set to False
if error, True if not.

Then call like this

Sub mMasterMacro()

On Error GoTo Exit_Me
Application.ScreenUpdating = False

'Run macros
If Not mMacro1 Then sErrors = serrors & £nMacro1" & vbnewline
If Not mMacro2 Then sErrors = serrors & £nMacro2" & vbnewline
If Not mMacro3 Then sErrors = serrors & £nMacro3" & vbnewline
If Not mMacro4 Then sErrors = serrors & £nMacro4" & vbnewline
If Not mMacro5 Then sErrors = serrors & £nMacro5" & vbnewline
If Not mMacro6 Then sErrors = serrors & £nMacro6" & vbnewline

If sErrors < "" then MsgBox sErrors

Exit_Me:
Application.ScreenUpdating = True

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Jason Morin" wrote in message
...
I have series of 6 macros I call with a master macro. I'd like all macros
to
run. If 1 or more macros errors out, I'd like it to move to the next macro
in
the sequence, then notify me at the end (with a msgbox) which macros
errored
out. Here's the basic construct. Thx.

Sub mMasterMacro()

On Error GoTo Exit_Me
Application.ScreenUpdating = False

'Run macros
mMacro1
mMacro2
mMacro3
mMacro4
mMacro5
mMacro6

Exit_Me:
Application.ScreenUpdating = True

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Flag me if macro errors

One way I've used is to call the macros as Functions rather than Subs.
For instance:

Public Sub mMasterMacro()
Dim sErr As String
Application.ScreenUpdating = False
If Not bFunction1 Then _
sErr = vbNewLine & "Error in Function1"
If Not bFunction2 Then _
sErr = sErr & vbNewLine & "Error in Function2"
If Not bFunction3 Then _
sErr = sErr & vbNewLine & "Error in Function3"
If Not bFunction4 Then _
sErr = sErr & vbNewLine & "Error in Function4"
If Not bFunction5 Then _
sErr = sErr & vbNewLine & "Error in Function5"
If Not bFunction6 Then _
sErr = sErr & vbNewLine & "Error in Function6"
If Len(sErr) < 0 Then _
MsgBox "There were errors:" & vbNewLine & sErr
Application.ScreenUpdating = True
End Sub

Private Function bFunction1() As Boolean
Dim bResult As Boolean
bResult = True 'Assume success!
On Error GoTo ErrHandler
'code here
ResumeHe
bFunction1 = bResult
Exit Function
ErrHandler:
bResult = False
'Additional error handling here
Resume ResumeHere
End Function

etc...




In article ,
Jason Morin wrote:

I have series of 6 macros I call with a master macro. I'd like all macros to
run. If 1 or more macros errors out, I'd like it to move to the next macro in
the sequence, then notify me at the end (with a msgbox) which macros errored
out. Here's the basic construct. Thx.

Sub mMasterMacro()

On Error GoTo Exit_Me
Application.ScreenUpdating = False

'Run macros
mMacro1
mMacro2
mMacro3
mMacro4
mMacro5
mMacro6

Exit_Me:
Application.ScreenUpdating = True

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Flag me if macro errors

If you don't want to change them to functions, here is another approach. The
called macros should have no internal error handling.

Sub mMasterMacro()
Dim i As Long, v As Variant
On Error GoTo ErrHandler
Application.ScreenUpdating = False
v = Array("mmacro1", "mmacro2", "mmacro3", _
"mmacro4", "mmacro5", "mmacro6")
'Run macros
i = 1
mMacro1
i = 2
mMacro2
i = 3
mmacro3
i = 4
mmacro4
i = 5
mmacro5
i = 6
mmacro6
MsgBox Left(s, Len(s) - 1) & " had problems"
Application.ScreenUpdating = True
ErrHandler:
s = s & v(i - 1) & ","
Resume Next

End Sub

Sub mMacro1()
r = 3 / 0
End Sub
Sub mMacro2()
r = 3
End Sub
Sub mmacro3()
r = 4 / 0
End Sub
Sub mmacro4()
r = 4
End Sub
Sub mmacro5()
r = 5 / 0
End Sub
Sub mmacro6()
r = 5
End Sub

--
Regards,
Tom Ogilvy


"Jason Morin" wrote:

I have series of 6 macros I call with a master macro. I'd like all macros to
run. If 1 or more macros errors out, I'd like it to move to the next macro in
the sequence, then notify me at the end (with a msgbox) which macros errored
out. Here's the basic construct. Thx.

Sub mMasterMacro()

On Error GoTo Exit_Me
Application.ScreenUpdating = False

'Run macros
mMacro1
mMacro2
mMacro3
mMacro4
mMacro5
mMacro6

Exit_Me:
Application.ScreenUpdating = True

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why can't I record "flag for follow up" as a Macro? Richard Hocking Excel Discussion (Misc queries) 7 September 14th 06 11:47 AM
macro errors Michelle Hanan Excel Programming 1 July 26th 06 06:21 PM
Macro Errors fugfug[_13_] Excel Programming 1 August 5th 05 02:05 PM
Macro Errors [email protected] Excel Programming 1 May 26th 05 12:28 PM
Rows to be moved from one flag to another flag jip Excel Programming 0 November 9th 04 02:21 PM


All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"