是否可以通过For Each循环找出OLEObject是否是ComboBox? 我在工作表上有几个Comboboxes,还有CommandButtons和其他什么。
Dim comboB As OLEObject
Dim ws As Worksheet: Set ws = ActiveSheet
For Each comboB in ws.OLEObjects
If typeName(comboB) = "ComboBox" Then
'Do something
End if
Next
问题是TypeName(stringvalue)仅适用于控件。 任何人都可以帮助我吗?
答案 0 :(得分:0)
尝试以下代码:
Sub sample()
Dim comboB As Variant
Dim ws As Worksheet
Set ws = ActiveSheet
With ws
For Each comboB In .OLEObjects
If TypeName(comboB.Object) = "ComboBox" Then
MsgBox TypeName(comboB) & " is a combo box"
End If
Next
End With
End Sub