ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Call UDF by String Name (https://www.excelbanter.com/excel-programming/390170-call-udf-string-name.html)

Hokievandal

Call UDF by String Name
 
I've made a custom object with a 'Function' method and need each instance of
the object to call a different UDF. Is there a way if I assign the UDF name
to the object's function as a string to call the function.

For example;
Public Function CalcRainfall(iDate as date) as double
'code to calculate rainfall...
End Function

Public Sub TestCalcRainfall()
Dim sUDF as string

sUDF = "CalcRainfall"

CustomObject.Function = sUDF
' code to run UDF

End Sub

Thanks,
Ryan



Bob Phillips

Call UDF by String Name
 
Public Function CalcRainfall(iDate As Date) As Double
'code to calculate rainfall...
End Function

Public Sub TestCalcRainfall()
Dim sUDF As String

sUDF = "CalcRainfall"

Application.Run sUDF, Date

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Hokievandal" wrote in message
...
I've made a custom object with a 'Function' method and need each instance
of
the object to call a different UDF. Is there a way if I assign the UDF
name
to the object's function as a string to call the function.

For example;
Public Function CalcRainfall(iDate as date) as double
'code to calculate rainfall...
End Function

Public Sub TestCalcRainfall()
Dim sUDF as string

sUDF = "CalcRainfall"

CustomObject.Function = sUDF
' code to run UDF

End Sub

Thanks,
Ryan





Hokievandal

Call UDF by String Name
 
Thanks Bob...

"Bob Phillips" wrote:

Public Function CalcRainfall(iDate As Date) As Double
'code to calculate rainfall...
End Function

Public Sub TestCalcRainfall()
Dim sUDF As String

sUDF = "CalcRainfall"

Application.Run sUDF, Date

End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Hokievandal" wrote in message
...
I've made a custom object with a 'Function' method and need each instance
of
the object to call a different UDF. Is there a way if I assign the UDF
name
to the object's function as a string to call the function.

For example;
Public Function CalcRainfall(iDate as date) as double
'code to calculate rainfall...
End Function

Public Sub TestCalcRainfall()
Dim sUDF as string

sUDF = "CalcRainfall"

CustomObject.Function = sUDF
' code to run UDF

End Sub

Thanks,
Ryan







All times are GMT +1. The time now is 05:10 PM.

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