![]() |
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 |
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 |
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 |
All times are GMT +1. The time now is 04:42 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com