Excel Vba Programaticly select vba userform element? RRS feed

  • Question

  • Hello.

    i am trying to find a way to get a peice of vba to do something similar to this psudocode

    Function something(name)

    find inside Userform1 an element called name and return its caption

    End Function

    I tried but it looks for something called 'name' instead of the name given

    any ideas?

    Much appriciated.

    Monday, February 4, 2013 12:45 PM

All replies

  • Try

    Function GetCaption(ControlName As String) As String
        On Error GoTo ErrHandler
        GetCaption = UserForm1.Controls(ControlName).Caption
        Exit Function
        GetCaption = "- not valid -"
    Exit Sub

    Regards, Hans Vogelaar

    • Proposed as answer by Rod Gill Monday, February 4, 2013 7:39 PM
    Monday, February 4, 2013 1:12 PM