I have a few activex combobox and vb code in excel sheet 1. But everytime after I open the workbook, I need to open the code window and run the code to activate the combobox. Is there any way that I can automatically activate and run the code in sheet 1, belonging to combobox, once I open the workbook?
I tried looking into other forums/questions but could not find any solution. sheet1.combobox1.activate in thisworkbook code is not working either. T
Following is the code that is in sheet 1 that needs to be activated.
Public oDictionary As Object
Private Sub ComboBox1_Click()
Dim r As Range
Dim list As Object
Set oDictionary = CreateObject("Scripting.Dictionary")
With Sheet2
For Each r In .Range("C11", .Cells(.Rows.Count, "c").End(xlUp))
If Not oDictionary.Exists(r.Text) Then
Set list = CreateObject("System.Collections.ArrayList")
oDictionary.Add r.Text, list
End If
If Not oDictionary(r.Text).Contains(r.Offset(0, 1).Value) Then
oDictionary(r.Text).Add r.Offset(0, 1).Value
End If
Next
End With
ComboBox1.list = oDictionary.Keys 'Display the list in combobox 1
End Sub