Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default 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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default 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.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Identifying a Control Type

Aha, I see. Thanks for informing me.


Arne
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
Process control chart for quality control in exel? Kara Charts and Charting in Excel 2 May 11th 10 05:45 PM
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
Excel spin box - no Control tab in Format Control dialong box tocoau Excel Worksheet Functions 7 August 10th 08 03:15 PM
Nested If statement to control format of number-type cells TB Excel Worksheet Functions 3 May 16th 08 01:35 AM
Difference between a Forms Control verus Active-X Control funGT350 Excel Discussion (Misc queries) 6 May 6th 08 11:20 PM


All times are GMT +1. The time now is 05:47 AM.

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"