ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Passing a Sub's name as parameter (https://www.excelbanter.com/excel-programming/332248-passing-subs-name-parameter.html)

Stefi

Passing a Sub's name as parameter
 
Hi All,
How can I pass the name of a Sub to be called to an other Sub (which is
expected to execute the call) as a parameter?
Stefi


keepITcool

Passing a Sub's name as parameter
 
Stefi..

do you mean s'thing like:

Sub ProcA()
dim s as String
select case Range("A1").Value
case 1: s="Proc1"
case 2: s="Proc2"
case else: msgbox "invalid input": exit sub
end select

call ProcB(s)
end sub

Sub ProcB(sSubProc as string)
'do 'common' stuff

if sSubProc = "Proc1" then
call Proc1
elseif sSubProc = "Proc2" then
call Proc2
end if
'note:could have used another select case above :)
end sub

sub proc1()
end sub
sub proc2()
end sub


Instead of passing the argument
you could use a module level variable.




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Stefi wrote :

Hi All,
How can I pass the name of a Sub to be called to an other Sub (which
is expected to execute the call) as a parameter?
Stefi


Leith Ross[_52_]

Passing a Sub's name as parameter
 

Hello Stefi,

Here is an example...

Sub Test(ByVal SubName As String)
Application.Run SubName
End Sub

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=38046


Stefi

Passing a Sub's name as parameter
 
Thanks Leith,
That was the very method I was looking for!
Regards,
Stefi

€˛Leith Ross€¯ ezt Ć*rta:


Hello Stefi,

Here is an example...

Sub Test(ByVal SubName As String)
Application.Run SubName
End Sub

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=380462



Sergey_vba

Passing a Sub's name as parameter
 

Hi all,

how can I end one procedure from another?

Thank you,
Sergey


--
Sergey_vba
------------------------------------------------------------------------
Sergey_vba's Profile: http://www.excelforum.com/member.php...o&userid=24437
View this thread: http://www.excelforum.com/showthread...hreadid=380462


K Dales[_2_]

Passing a Sub's name as parameter
 
In general, VBA will only execute one procedure at a time - if you call
another sub or function, execution of the first suspends until the one you
called is done. So I am not clear on what you want to do - please give more
details.

"Sergey_vba" wrote:


Hi all,

how can I end one procedure from another?

Thank you,
Sergey


--
Sergey_vba
------------------------------------------------------------------------
Sergey_vba's Profile: http://www.excelforum.com/member.php...o&userid=24437
View this thread: http://www.excelforum.com/showthread...hreadid=380462



Sergey_vba[_2_]

Passing a Sub's name as parameter
 

I have complicated code in which two procedures call each other man
times (without ending). This cycle may last quite long depending on th
value entered by user.

The sub will stop under certain conditions, but some times “call
stack” memory is not enough and I get “out of stack error”.

So when code “jumps” from Sub1 to Sub2, I’d like to End Sub1 fro
Sub2.

Thank you,
Sergey




In general, VBA will only execute one procedure at a time - if yo
call
another sub or function, execution of the first suspends until th
one you
called is done. So I am not clear on what you want to do - pleas
give more
details.


"Sergey_vba" wrote:



Hi all,

how can I end one procedure from another?

Thank you,
Sergey


--
Sergey_vb


--
Sergey_vb
-----------------------------------------------------------------------
Sergey_vba's Profile: http://www.excelforum.com/member.php...fo&userid=2443
View this thread: http://www.excelforum.com/showthread.php?threadid=38046


Chip Pearson

Passing a Sub's name as parameter
 
As I understand what you want to do, it can't be done.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Sergey_vba"
wrote
in message
...

I have complicated code in which two procedures call each other
many
times (without ending). This cycle may last quite long
depending on the
value entered by user.

The sub will stop under certain conditions, but some times
"calls
stack" memory is not enough and I get "out of stack error".

So when code "jumps" from Sub1 to Sub2, I'd like to End Sub1
from
Sub2.

Thank you,
Sergey




In general, VBA will only execute one procedure at a time - if
you
call
another sub or function, execution of the first suspends until
the
one you
called is done. So I am not clear on what you want to do -
please
give more
details.


"Sergey_vba" wrote:



Hi all,

how can I end one procedure from another?

Thank you,
Sergey


--
Sergey_vba



--
Sergey_vba
------------------------------------------------------------------------
Sergey_vba's Profile:
http://www.excelforum.com/member.php...o&userid=24437
View this thread:
http://www.excelforum.com/showthread...hreadid=380462





All times are GMT +1. The time now is 09:01 AM.

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