lxcc(虫莲)
Private Sub Command2_Click()
If TypeName(Me.Controls("command1")) = "CommandButton" Then
MsgBox "存在"
End If
End Sub
------------------------
这种写法如果不存在,则会保错!!还不如遍历之。
不好意思,写错了,使用For Each的使用不能再用Count属性,正确如下:
Dim ctl As Control
For Each ctl In Me.Controls
If (TypeOf ctl Is CommandButton) And (ctl.Name = "Command1") Then
MsgBox "按钮Command1存在"
End If
Next
Dim ctl As Control
For Each ctl In Me.Controls.Count
If (TypeOf ctl Is CommandButton) And (ctl.Name = "Command1") Then
MsgBox "按钮Command1存在"
End If
Next