ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   End a procedure from a different procedure (https://www.excelbanter.com/excel-programming/401623-end-procedure-different-procedure.html)

[email protected]

End a procedure from a different procedure
 
Hey guys, I'm writing a simulator that uses about a dozen different
procedures. In each procedure I have an Application.Run that sends the
compiler to a different procedure. When I run the macro, after awhile,
I get a "Run-Time error'28' Out of stack space". I think this comes
because I've nested to many procedures. I also don't want to return to
the old procedure after completing the new one. So my question: Is
there any way to end the old Sub immediately after transferring to the
new one? And will the variables remain intact if they are declared as
public in a separate module? If my question is a little confusing I'll
clarify if necessary. Thanks

Héctor Miguel

End a procedure from a different procedure
 
hi, (...) ?

... I'm writing a simulator that uses about a dozen different procedures.
In each procedure I have an Application.Run that sends the compiler to a different procedure.
When I run the macro, after awhile, I get a "Run-Time error'28' Out of stack space".
I think this comes because I've nested to many procedures.
I also don't want to return to the old procedure after completing the new one.
So my question: Is there any way to end the old Sub immediately after transferring to the new one?
And will the variables remain intact if they are declared as public in a separate module?
If my question is a little confusing I'll clarify if necessary. Thanks


instead using the Application.Run method you could try with Application.OnTime (i.e.)

Sub Macro1()
MsgBox "Starting chained procedures..."
Application.OnTime Now, "macro2"
MsgBox "Master procedure finished."
End Sub
Private Sub Macro2()
MsgBox "Starting secondary procedure..."
Application.OnTime Now, "macro3"
MsgBox "Secondary procedure finished."
End Sub
Private Sub Macro3()
MsgBox "Starting third procedure..."
Application.OnTime Now, "macro4"
MsgBox "Third procedure finished."
End Sub
Private Sub Macro4()
MsgBox "Starting fourth procedure..."
MsgBox "Fourth procedure finished."
End Sub

hth,
hector.



[email protected]

End a procedure from a different procedure
 
On Nov 24, 8:03 pm, "Héctor Miguel"
wrote:
hi, (...) ?

... I'm writing a simulator that uses about a dozen different procedures..
In each procedure I have an Application.Run that sends the compiler to a different procedure.
When I run the macro, after awhile, I get a "Run-Time error'28' Out of stack space".
I think this comes because I've nested to many procedures.
I also don't want to return to the old procedure after completing the new one.
So my question: Is there any way to end the old Sub immediately after transferring to the new one?
And will the variables remain intact if they are declared as public in a separate module?
If my question is a little confusing I'll clarify if necessary. Thanks


instead using the Application.Run method you could try with Application.OnTime (i.e.)

Sub Macro1()
MsgBox "Starting chained procedures..."
Application.OnTime Now, "macro2"
MsgBox "Master procedure finished."
End Sub
Private Sub Macro2()
MsgBox "Starting secondary procedure..."
Application.OnTime Now, "macro3"
MsgBox "Secondary procedure finished."
End Sub
Private Sub Macro3()
MsgBox "Starting third procedure..."
Application.OnTime Now, "macro4"
MsgBox "Third procedure finished."
End Sub
Private Sub Macro4()
MsgBox "Starting fourth procedure..."
MsgBox "Fourth procedure finished."
End Sub

hth,
hector.



added some Exit Sub's under the App.OnTime's and it works like a
charm. Thanks a lot


All times are GMT +1. The time now is 03:04 AM.

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