1

是否可以通过 For Each 循环找出 OLEObject 是否是 ComboBox?我在工作表上有几个组合框,还有命令按钮等等。

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) 仅适用于控件。谁能帮我?

4

1 回答 1

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
于 2013-06-07T10:15:34.360 回答