alexofrhodes
New Member
- Joined
- Sep 24, 2020
- Messages
- 24
- Office Version
- 2021
- Platform
- Windows
Hi all. I have the following code to get the selected controls on a userform's designer module.
The problem is that some controls are within a frame,
in which case the frame itself is added to the collection instead of the selected controls inside it.
I expect a similar problem to occur when intending to loop selected controls inside a MultiPage.
Any insight?
The problem is that some controls are within a frame,
in which case the frame itself is added to the collection instead of the selected controls inside it.
I expect a similar problem to occur when intending to loop selected controls inside a MultiPage.
Any insight?
VBA Code:
'needs reference to Microsoft Visual Basic for Applications Extensibility 5.3
Public Sub TestSelectedControls()
'go to a userform and call this from the immediate window
dim ctl as MSForms.Control
for each ctl in SelectedControls(Application.VBE.SelectedVBComponent)
debug.print ctl.name
next
End Sub
Function SelectedControls(FormModule as vbComponent) As Collection
Dim ctl As control
Dim out As New Collection
For Each ctl In FormModule.Designer.Selected
out.Add ctl
Next ctl
set SelectedControls=out
End Function