【发布时间】:2011-01-23 00:28:13
【问题描述】:
我需要将一个通用 VBA 表单控件对象转换为一个 ComboBox 对象,以便可以向其中添加项目。通用对象不允许我将项目插入现有列表中
Dim ctlCurrent As MSForms.Control
For Each ctlCurrent In frmItemInput.Controls
If TypeName(ctlCurrent) = "ComboBox" Then
Dim lbCurrentComboBox As MSForms.ComboBox
lbCurrentComboBox = ctlCurrent 'This is where the error occurs, when I try to convert one into another
' Adiciona os itens necessários
lbCurrentComboBox.AddItem ("R")
lbCurrentComboBox.AddItem ("D")
End If
Next ctlCurrent
我的问题是:我的表单中有大量组合框,我需要为所有组合框添加相同的选项。所以我想以编程方式做到这一点。
【问题讨论】:
-
追随者说得对。您需要使用 Set。