在VBA(Excel)中编程添加ComboBox [英] Programatically add ComboBox in VBA (Excel)
本文介绍了在VBA(Excel)中编程添加ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在VBA中创建,放置和填充ComboBox的元素。我不明白我失踪了,但我不可能知道如何做到。我 在我的API中有 MSForms
(即我不能写 Dim someComboBox As MSForms.ComboBox $ c $
I am trying to create, place and fill in elements of a ComboBox in VBA. I don't understand what I am missing, but I cannot possibly figure out how to do it. I do not have MSForms
in my API (i.e. I cannot write Dim someComboBox As MSForms.ComboBox
as it fails. Is it possible to import it somehow? Can someone point me in the right direction?
我想要实现的是,当用户点击一个
What I want to achieve is that when the user clicks a button a new form is created with various items (ComboBoxes, RadioButtons, etc.) and thus I want to do this programatically.
推荐答案
Set curCombo = ActiveSheet.Shapes.AddFormControl(xlDropDown, Left:=Cells(1, 1).Left, Top:=Cells(2, 1).Top, Width:=100, Height:=20)
With curCombo
.ControlFormat.DropDownLines = 2
.ControlFormat.AddItem "Item 1", 1
.ControlFormat.AddItem "item 2", 2
.Name = "myCombo"
.OnAction = "myCombo_Change"
End With
这篇关于在VBA(Excel)中编程添加ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文