![]() |
Identifying a Control Type
How do I identify what type of control I have on a form
Dim c As Control For Each c In UserForm1.Controls if c (is a text box) then some code Next c What goes in the brackets? Chrissy. |
Identifying a Control Type
Hi,
If TypeOf c Is Listbox then .... Heiko :-) "Chrissy" wrote: How do I identify what type of control I have on a form Dim c As Control For Each c In UserForm1.Controls if c (is a text box) then some code Next c What goes in the brackets? Chrissy. |
Identifying a Control Type
You also need to qualify the object type name with the MSForms type library or your code will be looking for different set of controls with the same name in the Excel type library, e.g.: If TypeOf c Is MSForms.ListBox then If TypeOf c Is MSForms.TextBox then etc.... -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * "Heiko" wrote in message ... Hi, If TypeOf c Is Listbox then ... Heiko :-) "Chrissy" wrote: How do I identify what type of control I have on a form Dim c As Control For Each c In UserForm1.Controls if c (is a text box) then some code Next c What goes in the brackets? Chrissy. |
Identifying a Control Type
I was not aware of the operator(?) TypeOf. Even though VBA
does consider it legal, I cannot find any help on it, and, what's more, it did not work in an example I had a look at (identifying a check box control on a form). It may depend on the sofware versions, I don't know. The following did work: Dim c As Control For Each c In UserForm1.Controls if TypeName(c)="TextBox" then some code Next c |
Identifying a Control Type
Hi Arne,
This section from the help topic on the If...Then...Else statement describes the TypeOf operator: An expression of the form TypeOf objectname Is objecttype. The objectname is any object reference and objecttype is any valid object type. The expression is True if objectname is of the object type specified by objecttype; otherwise it is False. -- Rob Bovey, MCSE, MCSD, Excel MVP Application Professionals http://www.appspro.com/ * Please post all replies to this newsgroup * * I delete all unsolicited e-mail responses * "Arne" wrote in message ... I was not aware of the operator(?) TypeOf. Even though VBA does consider it legal, I cannot find any help on it, and, what's more, it did not work in an example I had a look at (identifying a check box control on a form). It may depend on the sofware versions, I don't know. The following did work: Dim c As Control For Each c In UserForm1.Controls if TypeName(c)="TextBox" then some code Next c |
Identifying a Control Type
Aha, I see. Thanks for informing me.
Arne |
All times are GMT +1. The time now is 12:18 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com