-
Solved: How to Access Objects/Tools (ie ListBoxes) of a UserForm?
I want to be able to put various ToolBox Controls (ie TextBoxes and ListBoxes) of a UserForm into a collection, but I am not sure how to access/call specific controls.
For example, if I have three textboxes named Box1, Box2, and Box3, how can I put these into a collection so I can selectively turn off Box3 if it is not required, without creating explicit select/case logic.
Below is an example sub that I thought would work, VBComp is filtered to only examine UserForms, but I don't know how to go deeper to find the Controls on the userform. I thought VBComp.Collection would work, but it did not (for me)
[vba]Sub ListAllFormComponents()
Dim VBComp As VBComponent
Dim Msg As String
Dim CompItem As Object
For Each VBComp In ThisWorkbook.VBProject.VBComponents
If (VBComp.Type = vbext_ct_MSForm) Then
Msg = Msg & VBComp.name & vbCrLf
For Each CompItem In VBComp.Collection
Msg = Msg & vbTab & CompItem.name & vbCrLf
Next CompItem
End If
Next VBComp
MsgBox Prompt:=Msg
End Sub[/vba]
Last edited by nitt1995; 06-21-2006 at 09:29 AM.
Reason: clarification
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
Hi nitt,
Those items are referred to as controls in vba, so you would use:[vba]'For Each CompItem In VBComp.Collection
For Each CompItem In VBComp.Controls[/vba]Matt
-
-
Knowledge Base Approver
The King of Overkill!
VBAX Master
Glad to help! Gotta love the VBA syntax
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules