【问题标题】:Can't add item to combobox (form control) in vba excel无法在 vba excel 中将项目添加到组合框(表单控件)
【发布时间】:2020-07-02 16:08:38
【问题描述】:

我在sheet1 上有几个组合框(表单控件)。我想循环并填充它们。没有任何反应,每个 ComboBox 的列表中没有错误或没有项目。我使用此代码:

Sub cmbBox()
    Dim ctrl As Shape
    For Each ctrl In Sheet1.Shapes
        If ctrl.Type = msoOLEControlObject Then
            ctrl.AddItem "Done"
            ctrl.AddItem "Not Done"
        End If
    Next
End Sub

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    您可以直接循环通过 DropDowns(这是表单控件“组合框”的调用方式),而不是循环所有 Shapes ...

    Option Explicit
    
    Public Sub PopulateCombos()
        Dim dd As DropDown
        For Each dd In Sheet1.DropDowns
            dd.AddItem "Done"
            dd.AddItem "Not Done"
        Next dd
    End Sub
    

    【讨论】:

    • 谢谢!这对我帮助很大!
    猜你喜欢
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    相关资源
    最近更新 更多