Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Userform Objects

Can objects on a userform (eg. all labels or all command buttons) be treated
as a collection?

I have a userform with a large number of labels and I would like to perform
a similar operation on each label without naming them one by one in the code.

Thanks, Kaval
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Userform Objects

Hi Kaval,

Try something like:

Sub Tester()

Dim Ctrl As MSForms.Control
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.Label Then
'Do something: e.g.:
MsgBox Ctrl.Caption
Else
'Do something else
End If
Next Ctrl

End Sub


---
Regards,
Norman



"Kaval" wrote in message
...
Can objects on a userform (eg. all labels or all command buttons) be
treated
as a collection?

I have a userform with a large number of labels and I would like to
perform
a similar operation on each label without naming them one by one in the
code.

Thanks, Kaval



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Userform Objects

Hello Norman,

Let take the example to modifying the caption of a Label. Could you please
provide us a sample code.

The problem I am facing is that .Caption is not a property of Control and
its throwing me an error.
--
Akash Nath
Hewlett Packard India


"Norman Jones" wrote:

Hi Kaval,

Try something like:

Sub Tester()

Dim Ctrl As MSForms.Control
For Each Ctrl In UserForm1.Controls
If TypeOf Ctrl Is MSForms.Label Then
'Do something: e.g.:
MsgBox Ctrl.Caption
Else
'Do something else
End If
Next Ctrl

End Sub


---
Regards,
Norman



"Kaval" wrote in message
...
Can objects on a userform (eg. all labels or all command buttons) be
treated
as a collection?

I have a userform with a large number of labels and I would like to
perform
a similar operation on each label without naming them one by one in the
code.

Thanks, Kaval




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
Creating and controlling objects in a UserForm Stephen Knapp Excel Programming 0 November 24th 04 03:37 PM
Apply vba code to multiple userform objects sjoopie[_2_] Excel Programming 2 November 5th 04 01:42 PM
Apply vba code to multiple userform objects sjoopie Excel Programming 2 November 5th 04 12:15 PM
Unable to remove Sheet objects in the Microsoft Excel Objects Adrian[_7_] Excel Programming 1 August 26th 04 10:49 PM
Can you Copy Objects from a Worksheet to a Userform Dave Baranas Excel Programming 0 August 14th 03 07:48 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"