Reference Grouped ActiveX Controls Using a Variable

Sam Pickard

New Member
Joined
Apr 9, 2012
Messages
12
I have 32 checkboxes in a few different groups, each box is named EasyReviewXXXXXCheckbox where the Xs is a different 5 letter code for each box. I'm trying to find a way to reference them using a variable without ungrouping them. The code below seems to skip over any objects that are grouped, I know that if need be I can just ungroup them but If there's an easy way to include grouped objects I would much rather keep them together. Thanks in advance for any help.


Code:
Sub test()
    Dim obj As Object
    With ActiveSheet
        For Each obj In .OLEObjects
            If Left(obj.Name, 10) = "EasyReview" And Right(ct.Name, 5) = "Check" Then MsgBox (Mid(ct.Name, 10, 5))
        Next obj
    End With
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You could do something like this
Code:
   Dim shp                    As Shape
   Dim oGrp                   As GroupShapes
   Dim shpSub                 As Shape

   With ActiveSheet
      For Each shp In .Shapes
         On Error Resume Next
         Set oGrp = shp.GroupItems
         On Error GoTo 0
         If Not oGrp Is Nothing Then
            For Each shpSub In shp.GroupItems
               If Left(shpSub.Name, 10) = "EasyReview" And Right(shpSub.Name, 5) = "Check" Then MsgBox (Mid(shpSub.Name, 11, 5))
            Next shpSub
            Set oGrp = Nothing
         End If
      Next shp
   End With
 
Upvote 0
Thank you very much, that answered my question, unfortunately I made the assumption that if .name worked .value would also work and it doesn't seem like that is the case. Do you know if there's a way to pull out the value when using Shape? This is what I thought would work but the line in red gives me an "Object doesn't support this property or method" error.


Code:
   Dim shp                    As Shape
   Dim oGrp                   As GroupShapes
   Dim shpSub                 As Shape
   With ActiveSheet
      For Each shp In .Shapes
         On Error Resume Next
         Set oGrp = shp.GroupItems
         On Error GoTo 0
         If Not oGrp Is Nothing Then
            For Each shpSub In shp.GroupItems
               If Left(shpSub.Name, 10) = "EasyReview" And Right(shpSub.Name, 5) = "Check" Then
                  MsgBox (Mid(shpSub.Name, 11, 5))
[COLOR=#ff0000]                  If shpSub.Value = True Then MsgBox (Mid(shpSub.Name, 11, 5) & " Is True")
[/COLOR]               End If
            Next shpSub
            Set oGrp = Nothing
         End If
      Next shp   
   End With
 
Upvote 0
Nevermind, I figured out a way around this so I don't need to refer to each checkbox. Thank you very much for your help though RoryA
 
Upvote 0
Try:
Code:
If shpSub.oleformat.object.object.value = True
 
Upvote 0

Forum statistics

Threads
1,215,965
Messages
6,127,967
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top