Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

vba - Can't add items to a combobox

I have tried these sites for help:

Would appreciate the help!

Here is my code:

Private Sub FusegearPerformanceUserForm1()
    With FailureComboBox
        .AddItem "japp"
    End With
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Manipulation of controls in Excel confused me for a while until I realized that there are two kinds of them, and this might be part of your confusion. For example, there is:

  • a Form Control Combo Box, and,

  • an ActiveX Control Combo Box.

The two look, behave, and are controlled similarly, but not identically.

Click image to enlarge: differences between controls


I realize that wasn't your question, but I figured I should make sure you can identify which control you are using, and therefore make sure that you're using (and Googling) the correct information - especially since the terms "Combo Box" and "Drop Down Box" are often used interchangeably. A Google Search for Vcode related to BA Combo Box Control will be wrong 50% of the time, so you need to be more specific.


AS for the code difference:

FORM CONTROL Combo Box

'add item
ActiveWorkbook.Sheets("Sheet1").Shapes("Drop Down 1").ControlFormat.AddItem "abcd"

'remove all items
ActiveWorkbook.Sheets("Sheet1").Shapes("Drop Down 1").ControlFormat.RemoveAllItems


'https://analysistabs.com/vba-code/activex-controls/combobox/

ACTIVEX CONTROL Combo Box

'add item
ActiveWorkbook.Sheets("Sheet1").ComboBox1.AddItem "abcd"

'remove all items
ActiveWorkbook.Sheets("Sheet1").ComboBox1.Clear

More Information:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...