Home > Software engineering > Consult ace: Excel ActiveX combo box control, its name in the properties TAB, how the code changes?
Consult ace: Excel ActiveX combo box control, its name in the properties TAB, how the code changes?
Time:10-05
In the form of dynamically generate ActiveX combo box control, design mode, mouse the left key click generate combo box control, form the top left corner shows the control name (the default value is ComboBox1), the right mouse button click the combo box control, enter the attributes TAB,
Property card also has a name (the default value is ComboBox1); (according to excel help files, the ActiveX control on the working table has two names: one is contains the name of the graphics of the control, can view the work table, in the "name" box to see
The name; Another name is the code name of controls, can be in the "properties" window "(name)" on the right side of the cell to see the name, add controls to a worksheet for the first time, name and code name is matching, however, if one name
According to changed, another will not automatically change,); Now want to change this two names, online to find a sample code as follows, Sub InsertComboBox (), which is the CTL. The Name="Combo" can not run, tip: method 'Name'
Acting on the objects' IMdcCombo 'failure, Consult ace: how to solve the problem? Are there any other way by VBA code change control of the two names?
Sub InsertComboBox ()
Dim ole As OLEObject
Dim CTL boBox As MSForms.Com
Sheet2. Select
Cells (3, 5). Select
'insert combo box
The Set ole=Sheet2. OLEObjects. Add (ClassType:="Forms.Com boBox. 1")
Named '
Ole. Name="Combo"
Set CTL.=ole Object
CTL. Name="Combo"
CTL. AddItem "Item1 "
CTL. AddItem "Item2"
CTL. AddItem "Item3 "
CTL. ListIndex=0 'first project ListIndex is 0
'add a Click event, is omitted
End Sub
CodePudding user response:
Your tracking code?
Your mistake is not the name can't assign, but Cells (3, 5). Select Should be changed to: Sheet2. Cells (3, 5). Select