把form中的全部command(个数未知)的caption显示为"hallo"

来源:百度知道 编辑:UC知道 时间:2024/06/23 14:35:27
Private Sub form_Click()
For Each ? In Form1
get_caption ?
Next ?
End Sub

Sub get_caption(a As CommandButton)
a.Caption = "hello"
End Sub

好像是这样
?不知道添什么
用最佳答案能做出来但不是按我的要求。其他的都不行。但还是谢谢各位

Private Sub Form1_Click()
For Each i In Controls
If TypeOf i Is CommandButton Then
i.Caption = "hello"
End If
Next i
End Sub

Private Sub form_Click()
Dim b As CommandButton
For Each b In Form1
get_caption b
Next
End Sub

Sub get_caption(a As CommandButton)
a.Caption = "hello"
End Sub

Dim Com As CommandButton
For Each Com In Form1
Com.Caption = "hello"
Next

二楼正解。