【发布时间】:2020-07-08 18:23:00
【问题描述】:
我正在尝试循环通过在工作表的框架中组合在一起的 ActiveX 复选框。我已经能够找到所有复选框,但我无法通过 VBA 代码获取 GroupName 属性。为了弄清楚脚本,我一直在使用一个简单的工作簿,其中有两个复选框分组在一个框架中,它们被简单地命名为 Checkbox1 和 Checkbox2 并且它们具有相同的 GroupName。这就是我目前所拥有的
Sub test2()
Dim i As Integer
Dim cb As Object
Dim countItems As Integer
Dim checkBox As Object
For Each cb In ActiveSheet.Shapes
If cb.Name Like "Group*" Then
countItems = cb.GroupItems.Count
For i = 1 To countItems
If cb.GroupItems(i).Name Like "Check*" Then
Debug.Print cb.GroupItems(i).Name
End If
Next i
End If
Next cb
End Sub
我一直在互联网上搜索解决方案,但我看到的那些似乎不适合,因为我的复选框被组合在一起。
Sub test4()
Dim ole As OLEObject
For Each ole In ActiveSheet.OLEObjects
If TypeName(ole.Object) = "CheckBox" Then
Debug.Print ole.Object.GroupName
If ole.Object.GroupName = Group And ole.Object.Value = True Then
Debug.Print ole.Object.GroupName
End If
End If
Next ole
GroupClear = True
End Sub
这似乎可以找到工作表中的复选框很好但没有组合在一起。
感谢您的帮助
【问题讨论】:
-
Debug.Print cb.OLEFormat.Object.Object.GroupName在检查组名之前可能需要检查对象的类型...
标签: excel vba checkbox properties activex