Dim xx As Control For Each xx In Form1.Controls List1.AddItem xx.Name Next
'还可以判断控件数组 Private Sub Command1_Click() Dim x As VB.Control For Each x In Me.Controls If VBA.VarType(VBA.CallByName(Me, x.Name, VbGet)) = vbObject Then '控件数组 Debug.Print x.Name & ".Item(" & x.Index & ")" Else Debug.Print x.Name End If Next x End Sub
Dim obj As Object For Each obj In Me.Controls MsgBox obj.Name Next 比较简单
For Each xx In Form1.Controls
List1.AddItem xx.Name
Next
Private Sub Command1_Click()
Dim x As VB.Control
For Each x In Me.Controls
If VBA.VarType(VBA.CallByName(Me, x.Name, VbGet)) = vbObject Then '控件数组
Debug.Print x.Name & ".Item(" & x.Index & ")"
Else
Debug.Print x.Name
End If
Next x
End Sub
For Each obj In Me.Controls
MsgBox obj.Name
Next
比较简单