office交流網(wǎng)--QQ交流群號及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

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

微信交流群(請用微信掃碼)

        

Excel VBA窗體動(dòng)態(tài)創(chuàng)建控件(按鈕 標(biāo)簽 文本框 下拉框等)

2020-05-05 08:00:00
zstmtony
原創(chuàng)
15404

Excel VBA窗體動(dòng)態(tài)創(chuàng)建控件(按鈕  標(biāo)簽 文本框 下拉框等)

Excel窗體 如果能夠根據(jù)實(shí)際需要自動(dòng)生成各種控件,那將給程序帶來非常大的方便

Dim ctrLable As Control

Dim ctrTextBox As Control

Dim ctrComboBox As Control

Dim i As Integer

With Me

For i = 1 To 10

'添加標(biāo)簽控件 (Office中國交流網(wǎng))

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

With ctrLable

.Caption = "第" & i & "個(gè)標(biāo)簽"

.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 = "系統(tǒng)_庫位列表"

End With

Next i

End With

    分享
    文章分類
    聯(lián)系我們
    聯(lián)系人: 王先生
    Email: 18449932@qq.com
    QQ: 18449932
    微博: officecn01
    移動(dòng)訪問