Consulting

Results 1 to 3 of 3

Thread: Solved: calling a function according to a value in a variable

  1. #1
    VBAX Regular
    Joined
    Jan 2006
    Posts
    11
    Location

    Solved: calling a function according to a value in a variable

    as i said in my previous post 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:[VBA]
    dim functionName = string
    functionName = "doSomething"

    activesheet.functionName("and some arguments here")

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

    [/VBA]

    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!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    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
    [/vba]

  3. #3
    VBAX Regular
    Joined
    Jan 2006
    Posts
    11
    Location
    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) :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •