Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JH JH is offline
external usenet poster
 
Posts: 64
Default terminate a runnig macro

hello everybody

I'd like to end a macro that is being executed

if sth then
.....
else
macro would finish here

end if

application.quit
close an excel appl.
thanks

Jan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default terminate a runnig macro

if sth then
.....
else
exit sub

end if

application.quit

--
Regards,
Tom Ogilvy


"JH" wrote in message
...
hello everybody

I'd like to end a macro that is being executed

if sth then
....
else
macro would finish here

end if

application.quit
close an excel appl.
thanks

Jan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default terminate a runnig macro

try this

if something then exit sub------------<in one line
some other code
------------


no need of end if, no need of else if the first line is in one line
if something is not, then automatically it goes to the next line.

try and see.

JH wrote in message
...
hello everybody

I'd like to end a macro that is being executed

if sth then
....
else
macro would finish here

end if

application.quit
close an excel appl.
thanks

Jan



  #4   Report Post  
Posted to microsoft.public.excel.programming
JH JH is offline
external usenet poster
 
Posts: 64
Default terminate a runnig macro

Thank you Tom,
but Exit Sub terminate only the procedure in which it is
and just following sub goes on
and I'need to terminate the whole macro not only one sub

Jan


"Tom Ogilvy" wrote:

if sth then
.....
else
exit sub

end if

application.quit

--
Regards,
Tom Ogilvy


"JH" wrote in message
...
hello everybody

I'd like to end a macro that is being executed

if sth then
....
else
macro would finish here

end if

application.quit
close an excel appl.
thanks

Jan




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default terminate a runnig macro

The only command that halts code execution is

END

by itself.

This is a Hard stop, so it is usually not advised to use it (see help on
this command).

Better would be to design your code to facilitate what you want.

Use an argument in you sub that contains an indicator to stop

Main
Dim bFlag as boolean
'code
'code

mysub bFlag
if bFlag then exit sub

' code
' code
End Sub

Sub Mysub(bHalt as Boolean)

if condition then
bHalt = True
else
bHalt = false
end if
End Sub


"JH" wrote in message
...
Thank you Tom,
but Exit Sub terminate only the procedure in which it is
and just following sub goes on
and I'need to terminate the whole macro not only one sub

Jan


"Tom Ogilvy" wrote:

if sth then
.....
else
exit sub

end if

application.quit

--
Regards,
Tom Ogilvy


"JH" wrote in message
...
hello everybody

I'd like to end a macro that is being executed

if sth then
....
else
macro would finish here

end if

application.quit
close an excel appl.
thanks

Jan








  #6   Report Post  
Posted to microsoft.public.excel.programming
JH JH is offline
external usenet poster
 
Posts: 64
Default terminate a runnig macro

thanks

Jan



"Tom Ogilvy" wrote:

The only command that halts code execution is

END

by itself.

This is a Hard stop, so it is usually not advised to use it (see help on
this command).

Better would be to design your code to facilitate what you want.

Use an argument in you sub that contains an indicator to stop

Main
Dim bFlag as boolean
'code
'code

mysub bFlag
if bFlag then exit sub

' code
' code
End Sub

Sub Mysub(bHalt as Boolean)

if condition then
bHalt = True
else
bHalt = false
end if
End Sub


"JH" wrote in message
...
Thank you Tom,
but Exit Sub terminate only the procedure in which it is
and just following sub goes on
and I'need to terminate the whole macro not only one sub

Jan


"Tom Ogilvy" wrote:

if sth then
.....
else
exit sub

end if

application.quit

--
Regards,
Tom Ogilvy


"JH" wrote in message
...
hello everybody

I'd like to end a macro that is being executed

if sth then
....
else
macro would finish here

end if

application.quit
close an excel appl.
thanks

Jan







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default terminate a runnig macro

Then you need to set up a module level variable, say StopNow, and at the place
where you want to stop you write

Sub3(...)
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
terminate a form tkaplan Excel Discussion (Misc queries) 5 October 24th 05 01:14 PM
Runnig a macro when excel opens vman Excel Programming 3 December 18th 03 06:41 PM
Runnig macros in background mode Tom Ogilvy Excel Programming 0 August 6th 03 06:49 PM
Runnig macros in background mode Chip Pearson Excel Programming 0 August 6th 03 06:47 PM
Can't terminate the excel instance from VB Gerhard[_2_] Excel Programming 1 July 16th 03 11:06 AM


All times are GMT +1. The time now is 10:03 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"