在设计模式中循环遍历选定的UserForm控件



在Visual Basic编辑器中的Excel的即时窗口中,我可以像这样在设计模式中引用UserForm的控件,

?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.

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

最新更新