ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to call a function with variance which is function Name (https://www.excelbanter.com/excel-programming/308636-re-how-call-function-variance-function-name.html)

Jean-Yves[_2_]

how to call a function with variance which is function Name
 
Hi,


Use Run (to call a SUB, which is not a function)
A function return a value, not a sub


Sub test()
MsgBox "tesst"
End Sub

Sub testcall()
Dim str As String
str = "test"
Run str
End Sub

Regards,
Jean-Yves

"miao jie" wrote in message
...
Hi,
now I have a case to wanna use a string variance stand for function

name
to call a function, but I'm fail to do it. my test program as follow,
Sub test_call_function()
Dim functionName As String

functionName = "test_split_string"

' Call functionName("dss")
functionName "dss"
End Sub

Sub test_split_string(ByVal test As String)
Dim fieldArry
Dim i As Integer

fieldArry = Split("24354.54,34546.5,3324.67", ",")
For i = 0 To UBound(fieldArry, 1)
MsgBox fieldArry(i)
Next
MsgBox test
End Sub

the VBA tell me a compile error for
functionName "dss"

anyone can show me a way to use variance as function name to call it.

thanks
in advance.




Chip Pearson

how to call a function with variance which is function Name
 
Use Run (to call a SUB, which is not a function)

Run can be used to call a function as well as a sub.


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




"Jean-Yves" wrote in message
...
Hi,


Use Run (to call a SUB, which is not a function)
A function return a value, not a sub


Sub test()
MsgBox "tesst"
End Sub

Sub testcall()
Dim str As String
str = "test"
Run str
End Sub

Regards,
Jean-Yves

"miao jie" wrote in message
...
Hi,
now I have a case to wanna use a string variance stand for

function
name
to call a function, but I'm fail to do it. my test program as

follow,
Sub test_call_function()
Dim functionName As String

functionName = "test_split_string"

' Call functionName("dss")
functionName "dss"
End Sub

Sub test_split_string(ByVal test As String)
Dim fieldArry
Dim i As Integer

fieldArry = Split("24354.54,34546.5,3324.67", ",")
For i = 0 To UBound(fieldArry, 1)
MsgBox fieldArry(i)
Next
MsgBox test
End Sub

the VBA tell me a compile error for
functionName "dss"

anyone can show me a way to use variance as function name to

call it.
thanks
in advance.







All times are GMT +1. The time now is 09:21 PM.

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