terminate a runnig macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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
 
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
 
thanks

Jan



Tom Ogilvy said:
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
 
Then you need to set up a module level variable, say StopNow, and at the place
where you want to stop you write

Sub3(...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top