问题
I have tried these sites for help:
- excel-easy.com
- sitestory.dk
- ozgrid.com
- stackoverflow.com
- contextures.com
- microsoft.com
Would appreciate the help!
Here is my code:
Private Sub FusegearPerformanceUserForm1()
With FailureComboBox
.AddItem "japp"
End With
End Sub
回答1:
So, just for completion:
The solution to this question was, that the file was saved in the XLSX format which cannot contain VBA code. After saving the file in the XLSM format everything worked as expected.
回答2:
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:
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:
Different Types of Combo Boxes Explained
VBA ComboBox
MSDN : VBA Shape Members
来源:https://stackoverflow.com/questions/48949164/cant-add-items-to-a-combobox