I have some code that loops through the ActiveX controls on an Excel worksheet. This logs which checkboxes have been selected.
我有一些代码循环遍历Excel工作表上的ActiveX控件。此日志记录已选中的复选框。
Dim obj AS OLEObject
For Each obj In ActiveSheet.OLEObjects
If TypeName(obj.Object) = "CheckBox" Then ' loop through all checkboxes to find selections
BooCheck = obj.Object
If BooCheck = True Then
MyArray(j) = obj.Name 'if checkbox selected then store the associated Name
j = j + 1
End If
End If
Next obj
This all works fine. However, as I have a number of checkboxes that I need to move around I thought I'd group them together by Shift/click in design mode, right click and select the "Group" option. However, if I do this the grouped checkboxes vanish from OLEObjects. Where do they go? Is there a way of altering my code to find them when they are grouped?
这一切都没问题。但是,由于我有很多要移动的复选框,我想我应该在设计模式下通过Shift/click将它们组合在一起,右键单击并选择“group”选项。但是,如果我这样做,分组的复选框就会从OLEObjects中消失。他们去哪里?是否有一种方法可以改变我的代码,以便在它们分组时找到它们?
1 个解决方案
#1
1
The way to reference the OLEObjects is like this:
引用OLEObjects的方法是这样的:
Public Sub ReferenceTest(oSheet As Worksheet, sGroupName As String)
Dim i As Long
Dim oOle As OLEObject
With oSheet.Shapes.Range(sGroupName).GroupItems
For i = 1 To .Count
Set oOle = .Item(i).OLEFormat.Object
Debug.Print oOle.Name, oOle.Object.Value
Next i
End With
End Sub
Just specify the sheet and group name, e.g.
只需指定工作表和组名,例如。
ReferenceTest ActiveSheet, "Group 1"
#1
1
The way to reference the OLEObjects is like this:
引用OLEObjects的方法是这样的:
Public Sub ReferenceTest(oSheet As Worksheet, sGroupName As String)
Dim i As Long
Dim oOle As OLEObject
With oSheet.Shapes.Range(sGroupName).GroupItems
For i = 1 To .Count
Set oOle = .Item(i).OLEFormat.Object
Debug.Print oOle.Name, oOle.Object.Value
Next i
End With
End Sub
Just specify the sheet and group name, e.g.
只需指定工作表和组名,例如。
ReferenceTest ActiveSheet, "Group 1"