ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   generate sub dynamically (https://www.excelbanter.com/excel-programming/325144-generate-sub-dynamically.html)

Christian Galbavy[_2_]

generate sub dynamically
 
Hello!

I generate comboboxes dynamically in my code. Now I also want to manipulate
the approbriate Change-functions of these elements. Is this possible and
how?
For example, I insert a new comobox and name it "my_box".
Now I want to manipulate the function "my_box_Change" by my code.

Thanks for your answers!

Regards
Christian Galbavy




Bob Phillips[_6_]

generate sub dynamically
 
Christian,

Assuming a control toolbox combobox, here is an example of adding its click
event

With
ThisWorkbook.VBProject.VBComponents(Worksheets("Sh eet2").CodeName).CodeModul
e
.InsertLines .CreateEventProc("Click", "ComboBox1") + 1, _
vbTab & "If Range(""A1"").Value 0 Then " & vbCrLf & _
vbTab & vbTab & "Msgbox ""Hi""" & vbCrLf & _
vbTab & "End If"

End With

which will add this code

Private Sub ComboBox1_Click()
If Range("A1").Value 0 Then
MsgBox "Hi"
End If

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Christian Galbavy" wrote in message
...
Hello!

I generate comboboxes dynamically in my code. Now I also want to

manipulate
the approbriate Change-functions of these elements. Is this possible and
how?
For example, I insert a new comobox and name it "my_box".
Now I want to manipulate the function "my_box_Change" by my code.

Thanks for your answers!

Regards
Christian Galbavy







All times are GMT +1. The time now is 08:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com