Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default UserForm Controls Collection

Is there a way to "capture" all of the controls on a form that are of a
certain type. for example. Change the forecolor of all labels to Blue.

with my naming conventions i could probably do this with some kind of loop
since all my labels' names start with "lab", but i dont know how to identify
them in the controls collection as a specific type of control.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default UserForm Controls Collection

Dim Ctl As MSForms.Control

For Each Ctl In Form1.Controls
If TypeName(Ctl) = "Label" Then
'control code here
End If
Next Ctl

RBS

"Spencer" wrote in message
...
Is there a way to "capture" all of the controls on a form that are of a
certain type. for example. Change the forecolor of all labels to Blue.

with my naming conventions i could probably do this with some kind of loop
since all my labels' names start with "lab", but i dont know how to
identify
them in the controls collection as a specific type of control.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default UserForm Controls Collection

Another way:

Dim Ctl As MSForms.Control

For Each Ctl In Userform1.Controls
If TypeOf Ctl is MsForms.Label Then
'control code here
msgbox Ctl.name
End If
Next Ctl


Your original suggestion

for i = 0 to Userform1.controls.count - 1
if instr(1, me.Controls(i).name, "lab", vbTextCompare) = 1 then
msgbox me.controls(i).name
end if
Next


--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
Dim Ctl As MSForms.Control

For Each Ctl In Form1.Controls
If TypeName(Ctl) = "Label" Then
'control code here
End If
Next Ctl

RBS

"Spencer" wrote in message
...
Is there a way to "capture" all of the controls on a form that are of a
certain type. for example. Change the forecolor of all labels to Blue.

with my naming conventions i could probably do this with some kind of
loop
since all my labels' names start with "lab", but i dont know how to
identify
them in the controls collection as a specific type of control.




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
Create a collection of controls quartz[_2_] Excel Programming 7 November 2nd 05 10:16 PM
userform controls natanz[_2_] Excel Programming 3 November 2nd 05 02:38 PM
Userform Controls Nigel Excel Programming 5 December 30th 04 01:49 PM
Help please with UserForm controls sa3214 Excel Programming 4 July 2nd 04 03:00 AM
Add controls to UserForm Vyyk Drago Excel Programming 3 August 26th 03 01:22 PM


All times are GMT +1. The time now is 08:48 AM.

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

About Us

"It's about Microsoft Excel"