Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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" wrote in
message
...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default 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" wrote in
message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Sequence from Userform Control Nigel Excel Programming 3 December 29th 04 01:25 PM
Type of textbox on userform Lieven Mettepenningen[_2_] Excel Programming 2 October 15th 03 01:36 PM
Identifying a Control Type Chrissy[_4_] Excel Programming 5 July 30th 03 08:25 AM
UserForm Control John Wilson Excel Programming 0 July 16th 03 06:53 PM
UserForm Control Richard Choate Excel Programming 0 July 16th 03 06:50 PM


All times are GMT +1. The time now is 01:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"