none
vba discussion RRS feed

  • Question

  • hi,

    i have one userform and some modules(like module1,module2,module3).in that useform one combobox is there.  how can do write a code inside combobox... when click combobox ith come list of modules like (module1,module2,module).

    pls helpme

    thanks

    rammi

    Friday, August 8, 2014 1:57 AM

Answers

  • Hi,

    According to your description, the Combobox is in a userform, so I think you could resort to Initialize Event of UserForm to add the items to the Combobox control when loading the userform.

    Here is a sample for your reference. But please note that, there is no method of VBA language to get all the modules list automatically. So you have to bind the items into the Combobox one by one.

    Sub ComboBox1AddItem()
    ComboBox1.AddItem "Module1"
    ComboBox1.AddItem "Module2"
    ComboBox1.AddItem "Module3"
    End Sub
    
    Private Sub UserForm_Initialize()
    ComboBox1AddItem
    End Sub

    If you want to click the items of the Combobox to run the functions in the related modules. You could resort to Change event of the Combobox as followed.

    In Module1:

    Public Sub Message1()
    MsgBox "1"
    End Sub

    In UserForm1:

    Private Sub ComboBox1_Change()
    If ComboBox1.Text = "Module1" Then
        Message1
    End If
    End Sub


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 11, 2014 2:59 AM
    Moderator

All replies

  • Double click on the specific Combobox on the userform.  A sub will appear and you can write your code inside.

    Sub Combobox1 
    
    'code goes here
    End sub


    Please do not forget to click “Vote as Helpful” if the reply helps/directs you toward your solution and or "Mark as Answer" if it solves your question. This will help to contribute to the forum.

    Friday, August 8, 2014 6:41 PM
  • Hi,

    According to your description, the Combobox is in a userform, so I think you could resort to Initialize Event of UserForm to add the items to the Combobox control when loading the userform.

    Here is a sample for your reference. But please note that, there is no method of VBA language to get all the modules list automatically. So you have to bind the items into the Combobox one by one.

    Sub ComboBox1AddItem()
    ComboBox1.AddItem "Module1"
    ComboBox1.AddItem "Module2"
    ComboBox1.AddItem "Module3"
    End Sub
    
    Private Sub UserForm_Initialize()
    ComboBox1AddItem
    End Sub

    If you want to click the items of the Combobox to run the functions in the related modules. You could resort to Change event of the Combobox as followed.

    In Module1:

    Public Sub Message1()
    MsgBox "1"
    End Sub

    In UserForm1:

    Private Sub ComboBox1_Change()
    If ComboBox1.Text = "Module1" Then
        Message1
    End If
    End Sub


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 11, 2014 2:59 AM
    Moderator