+ Reply to Thread
Results 1 to 5 of 5

Userform Control Type

  1. #1
    VBA Dabbler
    Guest

    Userform Control Type

    I'm trying to step through a collection of controls on a userform and, based
    on type, take certain steps.

    Does anyone know the syntax for determining a userform control's 'type'?
    For example: is Control(i) a Textbox, Checkbox, Combobox, etc.

    Thanks,
    VBA Dabbler

  2. #2
    keepITcool
    Guest

    Re: Userform Control Type

    if you have vba6 (xl2000+)

    dim ctl as object
    for each ctl in me.controls
    use TypeOf ctl IS msforms.Combobox etc.
    intellisense will guide you... when you type in msforms.
    but you can leave it out afterwards..
    next

    if you need to code for xl97 use
    lcase(TypeName(ctl)) = "combobox" etc.

    the names for the classes can be found in the
    object browser in the msforms library.





    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    VBA Dabbler wrote :

    > I'm trying to step through a collection of controls on a userform
    > and, based on type, take certain steps.
    >
    > Does anyone know the syntax for determining a userform control's
    > 'type'? For example: is Control(i) a Textbox, Checkbox, Combobox,
    > etc.
    >
    > Thanks,
    > VBA Dabbler


  3. #3
    Chip Pearson
    Guest

    Re: Userform Control Type

    Use the TypeOf operator to determine the type of control. E.g.,

    Dim Ctrl As MSForms.Control
    For Each Ctrl In UserForm1.Controls
    If TypeOf Ctrl Is MSForms.CheckBox Then
    ' do something for checkbox
    ElseIf TypeOf Ctrl Is MSForms.ComboBox Then
    ' do something for combobox
    ElseIf TypeOf Ctrl Is MSForms.CommandButton Then
    ' do something for commandbutton
    '...
    End If
    Next Ctrl



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


    "VBA Dabbler" <[email protected]> wrote in
    message
    news:[email protected]...
    > I'm trying to step through a collection of controls on a
    > userform and, based
    > on type, take certain steps.
    >
    > Does anyone know the syntax for determining a userform
    > control's 'type'?
    > For example: is Control(i) a Textbox, Checkbox, Combobox, etc.
    >
    > Thanks,
    > VBA Dabbler




  4. #4
    VBA Dabbler
    Guest

    Re: Userform Control Type

    Great! Thanks for the suggestions, both work like a charm.

    "keepITcool" wrote:

    > if you have vba6 (xl2000+)
    >
    > dim ctl as object
    > for each ctl in me.controls
    > use TypeOf ctl IS msforms.Combobox etc.
    > intellisense will guide you... when you type in msforms.
    > but you can leave it out afterwards..
    > next
    >
    > if you need to code for xl97 use
    > lcase(TypeName(ctl)) = "combobox" etc.
    >
    > the names for the classes can be found in the
    > object browser in the msforms library.
    >
    >
    >
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > VBA Dabbler wrote :
    >
    > > I'm trying to step through a collection of controls on a userform
    > > and, based on type, take certain steps.
    > >
    > > Does anyone know the syntax for determining a userform control's
    > > 'type'? For example: is Control(i) a Textbox, Checkbox, Combobox,
    > > etc.
    > >
    > > Thanks,
    > > VBA Dabbler

    >


  5. #5
    VBA Dabbler
    Guest

    Re: Userform Control Type

    Chip,
    Thanks for your suggestions. I've used your example below and it work well.
    Regards,
    VBA Dabbler

    "Chip Pearson" wrote:

    > Use the TypeOf operator to determine the type of control. E.g.,
    >
    > Dim Ctrl As MSForms.Control
    > For Each Ctrl In UserForm1.Controls
    > If TypeOf Ctrl Is MSForms.CheckBox Then
    > ' do something for checkbox
    > ElseIf TypeOf Ctrl Is MSForms.ComboBox Then
    > ' do something for combobox
    > ElseIf TypeOf Ctrl Is MSForms.CommandButton Then
    > ' do something for commandbutton
    > '...
    > End If
    > Next Ctrl
    >
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    > "VBA Dabbler" <[email protected]> wrote in
    > message
    > news:[email protected]...
    > > I'm trying to step through a collection of controls on a
    > > userform and, based
    > > on type, take certain steps.
    > >
    > > Does anyone know the syntax for determining a userform
    > > control's 'type'?
    > > For example: is Control(i) a Textbox, Checkbox, Combobox, etc.
    > >
    > > Thanks,
    > > VBA Dabbler

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1