Userform Control Type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 :
 
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


message
news:[email protected]...
 
Chip,
Thanks for your suggestions. I've used your example below and it work well.
Regards,
VBA Dabbler
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top