萬盛學電腦網

 萬盛學電腦網 >> Excel教程 >> excel綜合 >> vba窗體在運行的時候動態添加控件的代碼

vba窗體在運行的時候動態添加控件的代碼

  一、動態添加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

copyright © 萬盛學電腦網 all rights reserved