如何设置组合框文本和值字段

时间:2022-11-29 20:23:39

How to set combo box text field and value field in Excel VBA, like we set for dropdown list in web applications, For example,

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

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

2 个解决方案

#1


1  

With ComboBox1 
   .AddItem "Item1" 
   .AddItem "Item2"
End With 

or

要么

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

#2


0  

When I've created an Excel ComboBox from Access VBA, I've used the following sytnax:

当我从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

But in Excel the two commented lines don't seem to work. Hope that helps?

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

#1


1  

With ComboBox1 
   .AddItem "Item1" 
   .AddItem "Item2"
End With 

or

要么

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

#2


0  

When I've created an Excel ComboBox from Access VBA, I've used the following sytnax:

当我从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

But in Excel the two commented lines don't seem to work. Hope that helps?

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