PDA

View Full Version : Solved: calling a function according to a value in a variable



Koesper
01-24-2006, 04:32 AM
as i said in my previous post (http://vbaexpress.com/forum/showthread.php?t=6796) i'm relatively new to VBA, and so i have a lot of questions...

the background:
i'm building a tool where my users can do several magical things to an excel workbook full of addresses. One of the important requirements is extensibility, and that means that i should be able to add new 'filters' quickly.
Therefore i want to define all the 'filters' in a separate worksheet.
One of the elements in a filter-definition is which vba function should be called, and which arguments should be passed to that function.

can anyone tell me how to evaluate a variable so it becomes a function name?

example:
dim functionName = string
functionName = "doSomething"

activesheet.functionName("and some arguments here")

sub doSomething(theArgument as string)
activeCell.value = theArgument
end sub



I hope you understand what i am trying to accomplish, and if you could tell me how i can get it to work, that would be great!

Bob Phillips
01-24-2006, 05:12 AM
Sub BeginItAll()
Dim functionName As String
functionName = "doSomething"

Application.Run functionName, "and some arguments here"

End Sub

Sub doSomething(theArgument As String)
MsgBox theArgument
End Sub

Koesper
01-24-2006, 06:06 AM
thanx XLD!
you solved my problem again!

I'm very happy! (untill i run into a new problem, but even then i'll know that somewhere someone has the anwser to all my problems) :-)