我需要将一个通用的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
我的问题是:我的表单中有大量的ComboBox,我需要为它们添加相同的选项。所以我想这样做。
答案 0 :(得分:15)
您可以使用SET“强制转换”VBA对象,例如:
SET lbCurrentComboBox = ctlCurrent
答案 1 :(得分:8)
如果phil's answer无效,请尝试
SET lbCurrentComboBox = ctlCurrent.Object