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

CodePudding user response:

The
refer to the original poster natureguard response:
... This code of CTL. Name="Combo" can't run...


If have a EMBED in the sheet (" Forms.Com boBox. 1 ", "") controls,

And Name is "Combo", then you add a control CTL, assignment Name="Combo",

When applied to object would be prompted to 'IMdcCombo' failure error message,

CodePudding user response:

reference 1st floor Topc008 response:
did you 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


Problem is not here, comment out the line of code CTL. The Name="Combo" normal operation, keep the lines of code, this error message

CodePudding user response:

refer to the second floor mingxyzonline response:
Quote: refer to the original poster natureguard response:

. This code of CTL. Name="Combo" can't run...


If have a EMBED in the sheet (" Forms.Com boBox. 1 ", "") controls,

And Name is "Combo", then you add a control CTL, assignment Name="Combo",

When applied to object would be prompted to 'IMdcCombo' failure error message,


Please look at the variables in the original definition, ole and CTL is different variables, so should be able to assign the same Name?

CodePudding user response:

Form the top left corner shows the control name and the name attribute TAB is one thing,

Under design condition, the selected controls, in the top left corner again after the modification of control name to the form control properties TAB, find the name has been changed

CodePudding user response:

reference 4 floor natureguard response:
please look at the variables in the original definition, ole and CTL is different variables, so should be able to assign the same Name?


Have been tested, the code the first time you run no problem, but to run for a second time just bounced,

CodePudding user response:

refer to 6th floor mingxyzonline response:
Quote: refer to 4th floor natureguard response:


Please look at the variables in the original definition, ole and CTL is different variables, so should be able to assign the same Name?


Have been tested, the code the first time you run no problem, but to run for a second time just bounced,


Yes, I don't know how to solve, so please have a look

CodePudding user response:

refer to 7th floor natureguard response:
yes, I don't know how to solve, so please take a look at


To determine whether a control name is empty, and then add controls give it a try,

CodePudding user response:

refer to the eighth floor mingxyzonline response:
Quote: refer to 7th floor natureguard response:

Yes, I don't know how to solve, so please take a look at


To determine whether a control name is empty, and then add controls give it a try,


Code the first run is no problem, but to run for a second time just bounced,

CodePudding user response:

references 9 f natureguard response:
code to run for the first time no problem, but to run for a second time just bounced,


You should learn the practice of VB, each running a ComboBox control name plus 1,

If Combo1, Combo2 Combo3...

So as not to appear the situation of the ComboBox control name repetition,

CodePudding user response:

references to the tenth floor mingxyzonline response:
code to run for the first time no problem, but to run for a second time just bounced,

You should learn the practice of VB, each running a ComboBox control name plus 1,

If Combo1, Combo2 Combo3...


Such as: CTL. Name="Combo" instead of

CTL. Name="Combo" & amp; ActiveSheet. Shapes. The Count
  •  Tags:  
  • VBA
  • Related