【发布时间】:2019-03-15 17:51:07
【问题描述】:
我在excel表1中有一些activex组合框和vb代码。但是每次打开工作簿后,我都需要打开代码窗口并运行代码来激活组合框。打开工作簿后,有什么方法可以自动激活并运行属于组合框的工作表 1 中的代码?
我尝试查看其他论坛/问题,但找不到任何解决方案。 此工作簿代码中的 sheet1.combobox1.activate 也不起作用。 T
以下是表格 1 中需要激活的代码。
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
【问题讨论】: