generate sub dynamically

C

Christian Galbavy

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
 
B

Bob Phillips

Christian,

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

With
ThisWorkbook.VBProject.VBComponents(Worksheets("Sheet2").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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top