Loop through selected UserForm controls in Design Mode

Viewed 60

In Excel's Immediate Window within the Visual Basic Editor, I can refer to controls of a UserForm in Design Mode like this,

?Application.VBE.SelectedVBComponent.Designer.Controls.Count

How do I loop through controls that are selected in Design Mode using a regular subroutine? For example, I'm working on a UserForm. Some of the controls are selected, but changing the properties of these controls using the Property Window is not an option. It must be done by code.

1 Answers

This is how you do it.


Dim lngControl As Long

With Application.VBE.SelectedVBComponent
    
    For lngControl = 0 To .Designer.Controls.Count - 1
        
        With .Designer.Selected.Item(lngControl)
            
            'Your code goes here
            
        End With
        
    Next lngControl
    
End With
Related