首页 > 办公 > Excel > 正文

vba窗体在运行的时候动态添加控件的代码

2024-08-23 19:28:19
字体:
来源:转载
供稿:网友

  一、动态添加CommandButton命令按钮

  Dim mc As CommandButton

  Static k

  k = k + 1

  Set mc = Me.Controls.Add("Forms.Commandbutton.1")

  mc.Caption = k

  mc.Top = Me.Controls(k - 1).Top + Me.Controls(k - 1).Height

  Me.Controls.Remove "Commandbutton1"

  二、动态添加文本框

  Set myText = Controls.Add( "VB.TextBox ", "myTextBox ")

  With myText

  .Visible = True

  .Text = "这是加载的动态控件 "

  .Width = 3200

  End With

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表