ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   terminate a runnig macro (https://www.excelbanter.com/excel-programming/322886-terminate-runnig-macro.html)

JH

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


Tom Ogilvy

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




R.VENKATARAMAN

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




JH

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





Tom Ogilvy

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







JH

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








Myrna Larson

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(...)


All times are GMT +1. The time now is 05:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com