Home > Software engineering >  Vba code to create or delete ActiveX control, public variable declaration and initialization module,
Vba code to create or delete ActiveX control, public variable declaration and initialization module,

Time:10-04

In the form of dynamically through code to generate ActiveX controls, and found that public variable declaration and initialization module, reset the; And dynamically through code to delete ActiveX control, public variable will be reset, that is, whether it's through the code to create or delete ActiveX controls, the other variable will be reset of the code, this is what reason, how to solve?


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:

Try:
Sheet2. OLEObjects. Add ClassType:="Forms.Com boBox. 1
"The Set ole=Sheet2. OLEObjects (" ComboBox1)

CodePudding user response:

Dim ole As OLEObject
Dim CTL boBox As MSForms.Com
Write in function?
  •  Tags:  
  • VBA