Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



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
Passing parameter to a query Dwaine Horton[_3_] Excel Programming 6 April 26th 05 02:24 AM
?Passing argument/parameter just starting[_2_] Excel Programming 0 October 23rd 04 07:56 PM
?Passing argument/parameter just starting Excel Programming 1 October 23rd 04 04:23 PM
Passing a parameter to Excel keepitcool Excel Programming 3 August 13th 03 03:57 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"