Can't add items to a combobox

喜欢而已 提交于 2019-12-17 16:41:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!