【问题标题】:How to set combo box text and value fields如何设置组合框文本和值字段
【发布时间】:2013-06-08 15:20:38
【问题描述】:

如何在 Excel VBA 中设置组合框文本字段和值字段,就像我们在 web 应用程序中设置下拉列表一样,例如,

DropdownList.DataTextField ="EmpName";
DropdownList.DataValueField = "EmpCode";

【问题讨论】:

    标签: c# asp.net vba excel


    【解决方案1】:
    With ComboBox1 
       .AddItem "Item1" 
       .AddItem "Item2"
    End With 
    

    ActiveSheet.Shapes("ComboBox1").ListFillRange = "A1:A10" 
    

    【讨论】:

    • mehow,上面的语句将为组合框的 text 和 value 属性设置相同的值。即 combobox.Text 和 combobox.Value 将返回“Item1”。我需要的是,combobox.Text 应该返回“Item1”,combobox.Value 应该返回 1。那么如何将这些值绑定到组合框。
    • 为什么要让 .Value 返回 1?你想达到什么目的
    【解决方案2】:

    当我从 Access VBA 创建 Excel ComboBox 时,我使用了以下 sytnax:

    With ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1")
        With .Object
            .TextAlign = 2
            '.LinkedCell = "D6"
            '.ListFillRange = "G16:G23"
        End With
    End With
    

    但在 Excel 中,这两条注释行似乎不起作用。希望有帮助吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-31
      • 2015-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多