动态添加控件
<p>Private Sub CommandButton1_Click()<br/>Dim jim As Control<br/>Set jim = Me.Controls.Add("vb.commandbutton")<br/>End Sub</p><p>我想在VBA里面动态添加控件,可是老是提示“无效的类别字符串”,请大家帮我看看,谢谢</p> 我在网上查了一下,试验结果:<br/><br/>Private WithEvents btn1 As CommandButton<br/><br/>Private Sub CommandButton1_Click()<br/> Dim jim As CommandButton<br/> Set jim = Me.Controls.Add("Forms.CommandButton.1", "btn1")<br/> <br/> With jim<br/> .Left = 20<br/> .top = 50<br/> <br/> End With<br/> <br/> Set btn1 = jim<br/>End Sub<br/><br/>Private Sub btn1_Click()<br/> MsgBox "hi"<br/>End Sub<br/> <p>谢谢,我刚才发现是帮助文档里的例子有错误</p><p>Set jim = Me.Controls.Add("Forms.CommandButton.1", "btn1")</p><p>帮助里是Set jim = Me.Controls.Add("MSForms.CommandButton.1", "btn1")</p>
页:
[1]