I'm a bit new to excel VBA and wondered if it is possible to pass a UDF
reference as an argument to a UDF as in:
Sub S1( subReference )
subRefrence()
End Sub
Sub S2()
End Sub
Call S1(S2)
If it can not be done cleanly, is there a workaround such as passing
the name of the function as an argument and then somehow evaluating it
inside the UDF?
Thanks for any clues.No, pass a key which is evaluatedSub S1( idx)
Select Case idx
Case 1 : Call S2
Case 2: Call S3
etc.
End Select
End Sub
Sub S2()
End Sub
Call S1(num)
--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
quot;puffquot; gt; wrote in message ups.com...
gt; I'm a bit new to excel VBA and wondered if it is possible to pass a UDF
gt; reference as an argument to a UDF as in:
gt;
gt; Sub S1( subReference )
gt; subRefrence()
gt; End Sub
gt;
gt; Sub S2()
gt; End Sub
gt;
gt; Call S1(S2)
gt;
gt; If it can not be done cleanly, is there a workaround such as passing
gt; the name of the function as an argument and then somehow evaluating it
gt; inside the UDF?
gt;
gt; Thanks for any clues.
gt;
First, this sounds like it's gonna cause a debugging nightmare, but this worked
for me.
A sub or a function???
Option Explicit
Sub testme()
Dim myStr As String
Dim myVar As Variant
myStr = quot;myFunctquot;
myVar = Application.Run(myStr, 12)
MsgBox myVar
myStr = quot;mySubquot;
Application.Run myStr
End Sub
Function myFunct(myLong As Long) As Long
myFunct = myLong * 3
End Function
Sub mysub()
MsgBox quot;hi from mysubquot;
End Sub
I don't think I'd use it.puff wrote:
gt;
gt; I'm a bit new to excel VBA and wondered if it is possible to pass a UDF
gt; reference as an argument to a UDF as in:
gt;
gt; Sub S1( subReference )
gt; subRefrence()
gt; End Sub
gt;
gt; Sub S2()
gt; End Sub
gt;
gt; Call S1(S2)
gt;
gt; If it can not be done cleanly, is there a workaround such as passing
gt; the name of the function as an argument and then somehow evaluating it
gt; inside the UDF?
gt;
gt; Thanks for any clues.
--
Dave Peterson
Thanks Dave, that is what I needed.
As to why, imagine a few hundred tables that must be build where the
code to build differs by only a few parameters AND a single function
that is unique to the table. One could make a general build routine
with a VERY LONG select or simply pass the function by name and run it
as you suggest. Coming from an environment where pointers and
references are generally available, I prefer the Run solution.
Thanks again.
- Dec 18 Thu 2008 20:47
Passing a UDF as an argument to a UDF
close
全站熱搜
留言列表
發表留言
留言列表

