Consulting

Results 1 to 3 of 3

Thread: Use a macro to stop to run other macros.

  1. #1

    Use a macro to stop to run other macros.

    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.

    [VBA]
    Sub run_A_to_C ()
    A
    B
    C
    End sub
    [/VBA]

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

    [VBA]
    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
    [/VBA]



    Thanks

  2. #2
    VBAX Regular
    Joined
    Dec 2007
    Posts
    21
    Location
    Try

    [vba]
    If wks Is Nothing Then
    End
    End If
    [/vba]
    Last edited by Aussiebear; 06-24-2012 at 02:56 PM. Reason: Corrected the tags surrounding the submitted code

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I would avoid using the draconian End in code, and control it by passback

    [VBA]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
    [/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •