office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Excel VBA窗體動態創建控件(按鈕 標籤 文本框 下拉框等)

2020-05-05 08:00:00
zstmtony
原創
461

Excel VBA窗體動態創建控件(按鈕  標籤 文本框 下拉框等)

Excel窗體 如果能夠根據實際需要自動生成各種控件,那將給程序帶來非常大的方便

Dim ctrLable As Control

Dim ctrTextBox As Control

Dim ctrComboBox As Control

Dim i As Integer

With Me

For i = 1 To 10

'添加標籤控件 (Office中國交流網)

Set ctrLable = .Controls.Add("Forms.Label.1", "LB" & i, True)

With ctrLable

.Caption = "第" & i & "箇標籤"

.Left = 10

.Top = 35 + (i - 1) * 35

.Tag = "AutoControl"

End With

'添加文本框控件 (tmtony)

Set ctrTextBox = .Controls.Add("Forms.TextBox.1", "Txt" & i, True)

With ctrTextBox

.Left = 10 + 50

.Top = 35 + (i - 1) * 35

.Width = 70

.Height = 20

.Tag = "AutoControl"

End With

'添加組閤框件

Set ctrComboBox = .Controls.Add("Forms.ComboBox.1", "Txt" & i, True)

With ctrComboBox

.Left = 10 + 50 + 70

.Top = 35 + (i - 1) * 35

.Width = 70

.Height = 20

.Tag = "AutoControl"

.RowSource = "繫統_庫位列錶"

End With

Next i

End With

    分享