+ Reply to Thread
Results 1 to 12 of 12

Ending session

  1. #1
    Freddie Mac
    Guest

    Ending session

    I have a macro that does alot of things. Sometimes I want to call a sub that
    ends the program for whatever reason. I dont know how to write this. My code
    is:

    Private Sub avbrytProgrammet(varDataSaknas)
    MsgBox ("Error 402. Program session aborted.")
    Me.End
    End Sub

    The line is wrong. How do you write this?

  2. #2
    NickHK
    Guest

    Re: Ending session

    Depending on exactly what you mean by "End session", there is:
    Exit Sub/Function - Stop execution the current routine
    ThisWorkbook.Close - Close the current WB
    Application.Quit - Close Excel

    NickHK

    "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > I have a macro that does alot of things. Sometimes I want to call a sub

    that
    > ends the program for whatever reason. I dont know how to write this. My

    code
    > is:
    >
    > Private Sub avbrytProgrammet(varDataSaknas)
    > MsgBox ("Error 402. Program session aborted.")
    > Me.End
    > End Sub
    >
    > The line is wrong. How do you write this?




  3. #3
    Freddie Mac
    Guest

    Re: Ending session

    yes I know. But I want to quit rĂșnning the macro. The workbook shall still be
    open..

    "NickHK" skrev:

    > Depending on exactly what you mean by "End session", there is:
    > Exit Sub/Function - Stop execution the current routine
    > ThisWorkbook.Close - Close the current WB
    > Application.Quit - Close Excel
    >
    > NickHK
    >
    > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > I have a macro that does alot of things. Sometimes I want to call a sub

    > that
    > > ends the program for whatever reason. I dont know how to write this. My

    > code
    > > is:
    > >
    > > Private Sub avbrytProgrammet(varDataSaknas)
    > > MsgBox ("Error 402. Program session aborted.")
    > > Me.End
    > > End Sub
    > >
    > > The line is wrong. How do you write this?

    >
    >
    >


  4. #4
    NickHK
    Guest

    Re: Ending session

    Exit Sub then

    NickHK

    "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > yes I know. But I want to quit rúnning the macro. The workbook shall still

    be
    > open..
    >
    > "NickHK" skrev:
    >
    > > Depending on exactly what you mean by "End session", there is:
    > > Exit Sub/Function - Stop execution the current routine
    > > ThisWorkbook.Close - Close the current WB
    > > Application.Quit - Close Excel
    > >
    > > NickHK
    > >
    > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > I have a macro that does alot of things. Sometimes I want to call a

    sub
    > > that
    > > > ends the program for whatever reason. I dont know how to write this.

    My
    > > code
    > > > is:
    > > >
    > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > MsgBox ("Error 402. Program session aborted.")
    > > > Me.End
    > > > End Sub
    > > >
    > > > The line is wrong. How do you write this?

    > >
    > >
    > >




  5. #5
    Freddie Mac
    Guest

    Re: Ending session

    well the sub is not the whole program. I have e.g. a main sub that calls
    other subs. In these subs I sometimes call the sub that I want to use for
    exiting the program. If I write exit sub I just exit the sub that is used for
    closing the program and I will return to where ever I was in the code. Is
    there no way of solving the problem?

    "NickHK" skrev:

    > Exit Sub then
    >
    > NickHK
    >
    > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > > yes I know. But I want to quit rĂșnning the macro. The workbook shall still

    > be
    > > open..
    > >
    > > "NickHK" skrev:
    > >
    > > > Depending on exactly what you mean by "End session", there is:
    > > > Exit Sub/Function - Stop execution the current routine
    > > > ThisWorkbook.Close - Close the current WB
    > > > Application.Quit - Close Excel
    > > >
    > > > NickHK
    > > >
    > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > > I have a macro that does alot of things. Sometimes I want to call a

    > sub
    > > > that
    > > > > ends the program for whatever reason. I dont know how to write this.

    > My
    > > > code
    > > > > is:
    > > > >
    > > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > > MsgBox ("Error 402. Program session aborted.")
    > > > > Me.End
    > > > > End Sub
    > > > >
    > > > > The line is wrong. How do you write this?
    > > >
    > > >
    > > >

    >
    >
    >


  6. #6
    NickHK
    Guest

    Re: Ending session

    If you have error trapping in your main sub, you can an error when you know
    you need to exit the whole code and the error will bubble up the the next
    active error trap. e.g.
    Sub Mainstart
    On Error Goto handler
    Call Macro1
    Exit Sub
    Handler:
    Select Case Err.Number
    Case 15000 'Or whatever err.number you use
    msgBox "Need to Quit"
    Case Else
    'Handle other errors
    End Select
    End Sub

    Sub macro1
    'Whatever code
    call macro2
    'More code
    End sub

    Sub macro2
    'Code...
    'Something happens that means needs to quit
    Err.raise 15000
    End

    NickHK

    "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    news:5A316069-596D-46CA-9595-0FBA9F05D70F@microsoft.com...
    > well the sub is not the whole program. I have e.g. a main sub that calls
    > other subs. In these subs I sometimes call the sub that I want to use for
    > exiting the program. If I write exit sub I just exit the sub that is used

    for
    > closing the program and I will return to where ever I was in the code. Is
    > there no way of solving the problem?
    >
    > "NickHK" skrev:
    >
    > > Exit Sub then
    > >
    > > NickHK
    > >
    > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > > > yes I know. But I want to quit rúnning the macro. The workbook shall

    still
    > > be
    > > > open..
    > > >
    > > > "NickHK" skrev:
    > > >
    > > > > Depending on exactly what you mean by "End session", there is:
    > > > > Exit Sub/Function - Stop execution the current routine
    > > > > ThisWorkbook.Close - Close the current WB
    > > > > Application.Quit - Close Excel
    > > > >
    > > > > NickHK
    > > > >
    > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    message
    > > > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > > > I have a macro that does alot of things. Sometimes I want to call

    a
    > > sub
    > > > > that
    > > > > > ends the program for whatever reason. I dont know how to write

    this.
    > > My
    > > > > code
    > > > > > is:
    > > > > >
    > > > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > > > MsgBox ("Error 402. Program session aborted.")
    > > > > > Me.End
    > > > > > End Sub
    > > > > >
    > > > > > The line is wrong. How do you write this?
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >




  7. #7
    Scoops
    Guest

    Re: Ending session


    Freddie Mac wrote:
    > well the sub is not the whole program. I have e.g. a main sub that calls
    > other subs. In these subs I sometimes call the sub that I want to use for
    > exiting the program. If I write exit sub I just exit the sub that is used for
    > closing the program and I will return to where ever I was in the code. Is
    > there no way of solving the problem?
    >


    Hi Freddie

    Check for the stop criteria in the parent routine.

    Regards

    Steve


  8. #8
    Freddie Mac
    Guest

    Re: Ending session

    Thanks that seems like a nice way to handle the problem. However when trying
    use your code I get "Unidentified etikett" (translation from swedish). My
    code looks like:

    Public Sub mainProgram()
    Dim x As String
    On Error GoTo handler
    Call worksheetMaker(x)
    ........
    Private Sub worksheetMaker(x As String)
    If .......
    Err.Raise 15000
    ........

    and I dont know how to write the handler but I tried:

    Private sub handler()
    Select Case Err.Number
    Case 15000
    MsgBox "Need to Quit"
    Case Else
    'Handle other errors
    End Select
    End Sub

    I am not very good at VB so please help me with this! I am most greatful for
    any assistance!

    "NickHK" skrev:

    > If you have error trapping in your main sub, you can an error when you know
    > you need to exit the whole code and the error will bubble up the the next
    > active error trap. e.g.
    > Sub Mainstart
    > On Error Goto handler
    > Call Macro1
    > Exit Sub
    > Handler:
    > Select Case Err.Number
    > Case 15000 'Or whatever err.number you use
    > msgBox "Need to Quit"
    > Case Else
    > 'Handle other errors
    > End Select
    > End Sub
    >
    > Sub macro1
    > 'Whatever code
    > call macro2
    > 'More code
    > End sub
    >
    > Sub macro2
    > 'Code...
    > 'Something happens that means needs to quit
    > Err.raise 15000
    > End
    >
    > NickHK
    >
    > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > news:5A316069-596D-46CA-9595-0FBA9F05D70F@microsoft.com...
    > > well the sub is not the whole program. I have e.g. a main sub that calls
    > > other subs. In these subs I sometimes call the sub that I want to use for
    > > exiting the program. If I write exit sub I just exit the sub that is used

    > for
    > > closing the program and I will return to where ever I was in the code. Is
    > > there no way of solving the problem?
    > >
    > > "NickHK" skrev:
    > >
    > > > Exit Sub then
    > > >
    > > > NickHK
    > > >
    > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > > news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > > > > yes I know. But I want to quit rĂșnning the macro. The workbook shall

    > still
    > > > be
    > > > > open..
    > > > >
    > > > > "NickHK" skrev:
    > > > >
    > > > > > Depending on exactly what you mean by "End session", there is:
    > > > > > Exit Sub/Function - Stop execution the current routine
    > > > > > ThisWorkbook.Close - Close the current WB
    > > > > > Application.Quit - Close Excel
    > > > > >
    > > > > > NickHK
    > > > > >
    > > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    > message
    > > > > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > > > > I have a macro that does alot of things. Sometimes I want to call

    > a
    > > > sub
    > > > > > that
    > > > > > > ends the program for whatever reason. I dont know how to write

    > this.
    > > > My
    > > > > > code
    > > > > > > is:
    > > > > > >
    > > > > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > > > > MsgBox ("Error 402. Program session aborted.")
    > > > > > > Me.End
    > > > > > > End Sub
    > > > > > >
    > > > > > > The line is wrong. How do you write this?
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >

    >
    >
    >


  9. #9
    NickHK
    Guest

    Re: Ending session

    The handler is not a separate routine, it is label within mainprogram,
    followed by a colon ":". So
    Sub MainProgram
    On Error Goto Handler
    '....Code
    Exit Sub 'So you do not execute the Handler normally
    Handler: '<<<<< Here
    Select case.... etc

    End Sub

    "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    news:26BDA2AB-D450-4ED6-8E93-CF6885CF4179@microsoft.com...
    > Thanks that seems like a nice way to handle the problem. However when

    trying
    > use your code I get "Unidentified etikett" (translation from swedish). My
    > code looks like:
    >
    > Public Sub mainProgram()
    > Dim x As String
    > On Error GoTo handler
    > Call worksheetMaker(x)
    > .......
    > Private Sub worksheetMaker(x As String)
    > If .......
    > Err.Raise 15000
    > .......
    >
    > and I dont know how to write the handler but I tried:
    >
    > Private sub handler()
    > Select Case Err.Number
    > Case 15000
    > MsgBox "Need to Quit"
    > Case Else
    > 'Handle other errors
    > End Select
    > End Sub
    >
    > I am not very good at VB so please help me with this! I am most greatful

    for
    > any assistance!
    >
    > "NickHK" skrev:
    >
    > > If you have error trapping in your main sub, you can an error when you

    know
    > > you need to exit the whole code and the error will bubble up the the

    next
    > > active error trap. e.g.
    > > Sub Mainstart
    > > On Error Goto handler
    > > Call Macro1
    > > Exit Sub
    > > Handler:
    > > Select Case Err.Number
    > > Case 15000 'Or whatever err.number you use
    > > msgBox "Need to Quit"
    > > Case Else
    > > 'Handle other errors
    > > End Select
    > > End Sub
    > >
    > > Sub macro1
    > > 'Whatever code
    > > call macro2
    > > 'More code
    > > End sub
    > >
    > > Sub macro2
    > > 'Code...
    > > 'Something happens that means needs to quit
    > > Err.raise 15000
    > > End
    > >
    > > NickHK
    > >
    > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > news:5A316069-596D-46CA-9595-0FBA9F05D70F@microsoft.com...
    > > > well the sub is not the whole program. I have e.g. a main sub that

    calls
    > > > other subs. In these subs I sometimes call the sub that I want to use

    for
    > > > exiting the program. If I write exit sub I just exit the sub that is

    used
    > > for
    > > > closing the program and I will return to where ever I was in the code.

    Is
    > > > there no way of solving the problem?
    > > >
    > > > "NickHK" skrev:
    > > >
    > > > > Exit Sub then
    > > > >
    > > > > NickHK
    > > > >
    > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    message
    > > > > news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > > > > > yes I know. But I want to quit rúnning the macro. The workbook

    shall
    > > still
    > > > > be
    > > > > > open..
    > > > > >
    > > > > > "NickHK" skrev:
    > > > > >
    > > > > > > Depending on exactly what you mean by "End session", there is:
    > > > > > > Exit Sub/Function - Stop execution the current routine
    > > > > > > ThisWorkbook.Close - Close the current WB
    > > > > > > Application.Quit - Close Excel
    > > > > > >
    > > > > > > NickHK
    > > > > > >
    > > > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    > > message
    > > > > > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > > > > > I have a macro that does alot of things. Sometimes I want to

    call
    > > a
    > > > > sub
    > > > > > > that
    > > > > > > > ends the program for whatever reason. I dont know how to write

    > > this.
    > > > > My
    > > > > > > code
    > > > > > > > is:
    > > > > > > >
    > > > > > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > > > > > MsgBox ("Error 402. Program session aborted.")
    > > > > > > > Me.End
    > > > > > > > End Sub
    > > > > > > >
    > > > > > > > The line is wrong. How do you write this?
    > > > > > >
    > > > > > >
    > > > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >




  10. #10
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    You can write some of the code in functions like:

    Function Task01(ByVal UserName as String) as Boolean

    If UserName <> "Administrator" Then
    Task01 = False
    Else
    Task01 = True
    End if

    End Function

    Then in your sub you can use

    If Not Task01 Then Exit Sub

  11. #11
    Freddie Mac
    Guest

    Re: Ending session

    Great it works just perfect! Thanks!!!! Is it possible to send varaibles to
    the error handler in some way? See i want to be able to send a varaible so i
    can use a messagebox that displays what is wrong. the same type of error
    occrus very often but with different variables. since i have many variables
    it is impossible to define an error case for each variable....would be great
    if you knew how to solve it!

    "NickHK" skrev:

    > The handler is not a separate routine, it is label within mainprogram,
    > followed by a colon ":". So
    > Sub MainProgram
    > On Error Goto Handler
    > '....Code
    > Exit Sub 'So you do not execute the Handler normally
    > Handler: '<<<<< Here
    > Select case.... etc
    >
    > End Sub
    >
    > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > news:26BDA2AB-D450-4ED6-8E93-CF6885CF4179@microsoft.com...
    > > Thanks that seems like a nice way to handle the problem. However when

    > trying
    > > use your code I get "Unidentified etikett" (translation from swedish). My
    > > code looks like:
    > >
    > > Public Sub mainProgram()
    > > Dim x As String
    > > On Error GoTo handler
    > > Call worksheetMaker(x)
    > > .......
    > > Private Sub worksheetMaker(x As String)
    > > If .......
    > > Err.Raise 15000
    > > .......
    > >
    > > and I dont know how to write the handler but I tried:
    > >
    > > Private sub handler()
    > > Select Case Err.Number
    > > Case 15000
    > > MsgBox "Need to Quit"
    > > Case Else
    > > 'Handle other errors
    > > End Select
    > > End Sub
    > >
    > > I am not very good at VB so please help me with this! I am most greatful

    > for
    > > any assistance!
    > >
    > > "NickHK" skrev:
    > >
    > > > If you have error trapping in your main sub, you can an error when you

    > know
    > > > you need to exit the whole code and the error will bubble up the the

    > next
    > > > active error trap. e.g.
    > > > Sub Mainstart
    > > > On Error Goto handler
    > > > Call Macro1
    > > > Exit Sub
    > > > Handler:
    > > > Select Case Err.Number
    > > > Case 15000 'Or whatever err.number you use
    > > > msgBox "Need to Quit"
    > > > Case Else
    > > > 'Handle other errors
    > > > End Select
    > > > End Sub
    > > >
    > > > Sub macro1
    > > > 'Whatever code
    > > > call macro2
    > > > 'More code
    > > > End sub
    > > >
    > > > Sub macro2
    > > > 'Code...
    > > > 'Something happens that means needs to quit
    > > > Err.raise 15000
    > > > End
    > > >
    > > > NickHK
    > > >
    > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > > news:5A316069-596D-46CA-9595-0FBA9F05D70F@microsoft.com...
    > > > > well the sub is not the whole program. I have e.g. a main sub that

    > calls
    > > > > other subs. In these subs I sometimes call the sub that I want to use

    > for
    > > > > exiting the program. If I write exit sub I just exit the sub that is

    > used
    > > > for
    > > > > closing the program and I will return to where ever I was in the code.

    > Is
    > > > > there no way of solving the problem?
    > > > >
    > > > > "NickHK" skrev:
    > > > >
    > > > > > Exit Sub then
    > > > > >
    > > > > > NickHK
    > > > > >
    > > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    > message
    > > > > > news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > > > > > > yes I know. But I want to quit rĂșnning the macro. The workbook

    > shall
    > > > still
    > > > > > be
    > > > > > > open..
    > > > > > >
    > > > > > > "NickHK" skrev:
    > > > > > >
    > > > > > > > Depending on exactly what you mean by "End session", there is:
    > > > > > > > Exit Sub/Function - Stop execution the current routine
    > > > > > > > ThisWorkbook.Close - Close the current WB
    > > > > > > > Application.Quit - Close Excel
    > > > > > > >
    > > > > > > > NickHK
    > > > > > > >
    > > > > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in
    > > > message
    > > > > > > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > > > > > > I have a macro that does alot of things. Sometimes I want to

    > call
    > > > a
    > > > > > sub
    > > > > > > > that
    > > > > > > > > ends the program for whatever reason. I dont know how to write
    > > > this.
    > > > > > My
    > > > > > > > code
    > > > > > > > > is:
    > > > > > > > >
    > > > > > > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > > > > > > MsgBox ("Error 402. Program session aborted.")
    > > > > > > > > Me.End
    > > > > > > > > End Sub
    > > > > > > > >
    > > > > > > > > The line is wrong. How do you write this?
    > > > > > > >
    > > > > > > >
    > > > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >

    >
    >
    >


  12. #12
    NickHK
    Guest

    Re: Ending session

    You can either use a global variable.
    Look at the full syntax for Err.Raise, as there are other arguments that may
    be useful.

    Or use the functionality outlined by Kaak to pass info back in a return
    value, check its value after the call and progressing backwards.

    NickHK

    "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    news:F700483A-85B4-4FDE-B5A2-A3A4E872F380@microsoft.com...
    > Great it works just perfect! Thanks!!!! Is it possible to send varaibles

    to
    > the error handler in some way? See i want to be able to send a varaible so

    i
    > can use a messagebox that displays what is wrong. the same type of error
    > occrus very often but with different variables. since i have many

    variables
    > it is impossible to define an error case for each variable....would be

    great
    > if you knew how to solve it!
    >
    > "NickHK" skrev:
    >
    > > The handler is not a separate routine, it is label within mainprogram,
    > > followed by a colon ":". So
    > > Sub MainProgram
    > > On Error Goto Handler
    > > '....Code
    > > Exit Sub 'So you do not execute the Handler normally
    > > Handler: '<<<<< Here
    > > Select case.... etc
    > >
    > > End Sub
    > >
    > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in message
    > > news:26BDA2AB-D450-4ED6-8E93-CF6885CF4179@microsoft.com...
    > > > Thanks that seems like a nice way to handle the problem. However when

    > > trying
    > > > use your code I get "Unidentified etikett" (translation from swedish).

    My
    > > > code looks like:
    > > >
    > > > Public Sub mainProgram()
    > > > Dim x As String
    > > > On Error GoTo handler
    > > > Call worksheetMaker(x)
    > > > .......
    > > > Private Sub worksheetMaker(x As String)
    > > > If .......
    > > > Err.Raise 15000
    > > > .......
    > > >
    > > > and I dont know how to write the handler but I tried:
    > > >
    > > > Private sub handler()
    > > > Select Case Err.Number
    > > > Case 15000
    > > > MsgBox "Need to Quit"
    > > > Case Else
    > > > 'Handle other errors
    > > > End Select
    > > > End Sub
    > > >
    > > > I am not very good at VB so please help me with this! I am most

    greatful
    > > for
    > > > any assistance!
    > > >
    > > > "NickHK" skrev:
    > > >
    > > > > If you have error trapping in your main sub, you can an error when

    you
    > > know
    > > > > you need to exit the whole code and the error will bubble up the the

    > > next
    > > > > active error trap. e.g.
    > > > > Sub Mainstart
    > > > > On Error Goto handler
    > > > > Call Macro1
    > > > > Exit Sub
    > > > > Handler:
    > > > > Select Case Err.Number
    > > > > Case 15000 'Or whatever err.number you use
    > > > > msgBox "Need to Quit"
    > > > > Case Else
    > > > > 'Handle other errors
    > > > > End Select
    > > > > End Sub
    > > > >
    > > > > Sub macro1
    > > > > 'Whatever code
    > > > > call macro2
    > > > > 'More code
    > > > > End sub
    > > > >
    > > > > Sub macro2
    > > > > 'Code...
    > > > > 'Something happens that means needs to quit
    > > > > Err.raise 15000
    > > > > End
    > > > >
    > > > > NickHK
    > > > >
    > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    message
    > > > > news:5A316069-596D-46CA-9595-0FBA9F05D70F@microsoft.com...
    > > > > > well the sub is not the whole program. I have e.g. a main sub that

    > > calls
    > > > > > other subs. In these subs I sometimes call the sub that I want to

    use
    > > for
    > > > > > exiting the program. If I write exit sub I just exit the sub that

    is
    > > used
    > > > > for
    > > > > > closing the program and I will return to where ever I was in the

    code.
    > > Is
    > > > > > there no way of solving the problem?
    > > > > >
    > > > > > "NickHK" skrev:
    > > > > >
    > > > > > > Exit Sub then
    > > > > > >
    > > > > > > NickHK
    > > > > > >
    > > > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote in

    > > message
    > > > > > > news:839E2979-62B2-4D8E-8DD3-3D58878E88FB@microsoft.com...
    > > > > > > > yes I know. But I want to quit rúnning the macro. The workbook

    > > shall
    > > > > still
    > > > > > > be
    > > > > > > > open..
    > > > > > > >
    > > > > > > > "NickHK" skrev:
    > > > > > > >
    > > > > > > > > Depending on exactly what you mean by "End session", there

    is:
    > > > > > > > > Exit Sub/Function - Stop execution the current routine
    > > > > > > > > ThisWorkbook.Close - Close the current WB
    > > > > > > > > Application.Quit - Close Excel
    > > > > > > > >
    > > > > > > > > NickHK
    > > > > > > > >
    > > > > > > > > "Freddie Mac" <FreddieMac@discussions.microsoft.com> wrote

    in
    > > > > message
    > > > > > > > > news:9740CAD1-8713-4999-9268-E46CE5CC3C86@microsoft.com...
    > > > > > > > > > I have a macro that does alot of things. Sometimes I want

    to
    > > call
    > > > > a
    > > > > > > sub
    > > > > > > > > that
    > > > > > > > > > ends the program for whatever reason. I dont know how to

    write
    > > > > this.
    > > > > > > My
    > > > > > > > > code
    > > > > > > > > > is:
    > > > > > > > > >
    > > > > > > > > > Private Sub avbrytProgrammet(varDataSaknas)
    > > > > > > > > > MsgBox ("Error 402. Program session aborted.")
    > > > > > > > > > Me.End
    > > > > > > > > > End Sub
    > > > > > > > > >
    > > > > > > > > > The line is wrong. How do you write this?
    > > > > > > > >
    > > > > > > > >
    > > > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1