PDA

View Full Version : Use a macro to stop to run other macros.



uktous
06-24-2012, 06:29 AM
Hi,

The macro “run_A_to_C" contains 3 macros – A, B, and C.

I hope that macro A can perform this function:
If sheets(“sheet1”) doesn’t exist, then stop running macro run A_to_C.

Note: not just stop running macro A.


Sub run_A_to_C ()
A
B
C
End sub


the following macro A can exit macro A only, but can't exit macro "run A_to_C".


Sub A()

On Error Resume Next
Set wks = Worksheets("Sheet1")

On Error Goto 0

If wks Is Nothing Then
Exit sub
End If

End Sub




Thanks

VoG
06-24-2012, 06:39 AM
Try


If wks Is Nothing Then
End
End If

Bob Phillips
06-24-2012, 03:29 PM
I would avoid using the draconian End in code, and control it by passback

Sub run_A_to_C()
If A Then

Call B
Call C
End If
End Sub

Function A() As Boolean

On Error Resume Next
Set wks = Worksheets("Sheet1")
On Error GoTo 0

A = Not wks Is Nothing
End Function