Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Ending session

Exit Sub then

NickHK

"Freddie Mac" wrote in message
...
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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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" wrote in message
...
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" wrote in message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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" wrote in message
...
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" wrote in message
...
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" wrote in

message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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

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
Macro to run RDP session alistew Excel Discussion (Misc queries) 0 February 22nd 08 11:27 AM
Host Session Emulation [email protected] Excel Worksheet Functions 0 December 27th 06 05:47 PM
Startup and template locations in Citrix TS session and local session John Nurick Setting up and Configuration of Excel 2 September 21st 06 10:42 PM
Start a new session when a session is already opend MD Excel Programming 1 December 17th 05 05:47 PM
New Workbook New Session RWThomas Excel Programming 0 January 7th 04 05:56 PM


All times are GMT +1. The time now is 02:58 AM.

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

About Us

"It's about Microsoft Excel"