尝试在Excel中创建然后在vba中填充Activex组合框时出现问题。下面的代码在作为两个单独的宏运行时有效,但是当我尝试将两个宏放在一起时,将创建一个空的组合框。谁能告诉我这是为什么,以及如何克服这个问题?
提前致谢,
JW
Sub CreateComboBox1()
'Creating ComboBox1:
ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", _
Link:=False, DisplayAsIcon:=False, Left:=50, Top:=80, Width:=100, _
Height:=15).Select
End Sub
Sub PopulateComboBox1()
'Populating ComboBox1
Sheet1.ComboBox1.AddItem "Date", 0
Sheet1.ComboBox1.AddItem "Player", 1
Sheet1.ComboBox1.AddItem "Team", 2
Sheet1.ComboBox1.AddItem "Goals", 3
Sheet1.ComboBox1.AddItem "Number", 4
End
最佳答案
试试这个
Sub CreateComboBox1()
With ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", _
Link:=False, DisplayAsIcon:=False, Left:=50, Top:=80, Width:=100, _
Height:=15)
With .Object
.AddItem "Date"
.AddItem "Player"
.AddItem "Team"
.AddItem "Goals"
.AddItem "Number"
End With
End With
End Sub
关于excel-vba - 如何在Excel中使用vba创建和填充Activex组合框。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11692816/