Vba 使用宏在excel中显示多个组合框
我想在excel中的行中显示大约100个组合框 如何使用循环迭代编写宏代码,而不是像这样逐个编写宏代码:Vba 使用宏在excel中显示多个组合框,vba,excel,combobox,Vba,Excel,Combobox,我想在excel中的行中显示大约100个组合框 如何使用循环迭代编写宏代码,而不是像这样逐个编写宏代码: with combobox1 .additem("stuff 1") .additem("stuff 2") end with with combobox2 .additem("stuff 1") .additem("stuff 2") end with . .. with combobox100 .additem("stuff 1") .additem
with combobox1
.additem("stuff 1")
.additem("stuff 2")
end with
with combobox2
.additem("stuff 1")
.additem("stuff 2")
end with
.
..
with combobox100
.additem("stuff 1")
.additem("stuff 2")
end with
For Each s In OLEObjects
If s.OLEType = 2 And s.progID = "Forms.ComboBox.1" Then
' do your stuff
s.Object.AddItem ("Stuff 1")
End If
Next
我知道这不是一个有效的方法。如何写循环???我试过了,但没用
for i = 1 to 100
with combobox & i
.additem("stuff 1")
.additem("stuff 2")
end with
next i
谢谢。只要它们是ActiveX组合框,您就可以这样做:
with combobox1
.additem("stuff 1")
.additem("stuff 2")
end with
with combobox2
.additem("stuff 1")
.additem("stuff 2")
end with
.
..
with combobox100
.additem("stuff 1")
.additem("stuff 2")
end with
For Each s In OLEObjects
If s.OLEType = 2 And s.progID = "Forms.ComboBox.1" Then
' do your stuff
s.Object.AddItem ("Stuff 1")
End If
Next
或使用“形状”集合访问组合框:
For Each s In Shapes
If s.Type = msoOLEControlObject Then
If s.OLEFormat.progID = "Forms.ComboBox.1" Then
s.OLEFormat.Object.Object.AddItem ("Stuff 1")
End If
End If
Next
非常感谢。它起作用了。下一步我只需要学习对象。。感谢