Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default referencing forms controls

I have a series of labels on a form that I want to change the text
color on programatically.
If the label names are like 'label1', 'label2','label3', is there a a
way to loop through them?

Albert Wang

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default referencing forms controls


You can loop through them as members of the Controls collection

Dim ctl As Control

For Each ctl In Me.Controls

If ctl.Name = "Label2" Then
Me.Label2.ForeColor = vbRed
End If
Next ctl

--
Kevin Backmann


"AlbertYWang" wrote:

I have a series of labels on a form that I want to change the text
color on programatically.
If the label names are like 'label1', 'label2','label3', is there a a
way to loop through them?

Albert Wang


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default referencing forms controls

some added info:

Dim ctl As Control

For Each ctl In Me.Controls
if typeof ctl is MSForms.Label then
Me.Label2.ForeColor = vbGreen
End If
Next ctl

or

for i = 1 to 5
me.controls("Label" & i).ForeColor = RGB(0,255,0)
Next

--
Regards,
Tom Ogilvy

"Kevin B" wrote in message
...

You can loop through them as members of the Controls collection

Dim ctl As Control

For Each ctl In Me.Controls

If ctl.Name = "Label2" Then
Me.Label2.ForeColor = vbRed
End If
Next ctl

--
Kevin Backmann


"AlbertYWang" wrote:

I have a series of labels on a form that I want to change the text
color on programatically.
If the label names are like 'label1', 'label2','label3', is there a a
way to loop through them?

Albert Wang




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default referencing forms controls

Thanks Kevin and Tom.
That's exactly what I needed.

Albert Wang

Tom Ogilvy wrote:
some added info:

Dim ctl As Control

For Each ctl In Me.Controls
if typeof ctl is MSForms.Label then
Me.Label2.ForeColor = vbGreen
End If
Next ctl

or

for i = 1 to 5
me.controls("Label" & i).ForeColor = RGB(0,255,0)
Next

--
Regards,
Tom Ogilvy

"Kevin B" wrote in message
...

You can loop through them as members of the Controls collection

Dim ctl As Control

For Each ctl In Me.Controls

If ctl.Name = "Label2" Then
Me.Label2.ForeColor = vbRed
End If
Next ctl

--
Kevin Backmann


"AlbertYWang" wrote:

I have a series of labels on a form that I want to change the text
color on programatically.
If the label names are like 'label1', 'label2','label3', is there a a
way to loop through them?

Albert Wang



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
Questions about Forms & Controls hmm Excel Discussion (Misc queries) 3 December 20th 06 01:06 PM
Forms controls Catalin Excel Worksheet Functions 2 May 11th 06 03:44 PM
Forms Controls Larry Dodd Excel Programming 4 March 27th 05 11:39 AM
diference between FORMS & CONTROLS Marek Excel Programming 3 September 5th 04 07:53 AM
Forms Controls Chuck Taylor Excel Programming 2 December 1st 03 01:42 PM


All times are GMT +1. The time now is 11:12 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"