office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

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

Excel VBA窗体动态创建控件(按钮 标签 文本框 下拉框等)

2020-05-05 08:00:00
zstmtony
原创
14305

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

    分享