可以使用CallByName函数根据菜单名称调用Click方法,不过你必须将Menu的Click方法声明为公有的 Private Sub Command1_Click() Dim c As Control For Each c In Controls If TypeName(c) = "Menu" Then If c.Caption = Text1.Text Then CallByName Me, c.Name & "_Click", VbMethod Exit For End If End If Next c End Sub
Private Sub Command1_Click()
Dim c As Control
For Each c In Controls
If TypeName(c) = "Menu" Then
If c.Caption = Text1.Text Then
CallByName Me, c.Name & "_Click", VbMethod
Exit For
End If
End If
Next c
End Sub