View Full Version : [SOLVED:] Determine selected item in GroupItems
Cosmo
07-20-2012, 12:16 PM
I need to run an action on the current selection, but if the selection is one or more items in a group (note - NOT the group itself), I need to run the action on those items individually. The Shape.Type property comes up as a group whether it is the group itself selected, or a single item in the group. I looked to see if I could loop through the group items to determine which of them were selected, but haven't seen a way to do so.
Is there any way to determine which items in a group are selected and which are not?
John Wilson
07-21-2012, 05:06 AM
You always have the good questions Mark!
AFAIK there's no sensible way to check this.
Here's a possible not sensible way:
Sub Silly_chex()
Dim myTop() As Single
Dim grpTop As Single
Dim i As Integer
Dim strResult As String
Dim oshp As Shape
ReDim myTop(1 To 1)
Set oshp = ActiveWindow.Selection.ShapeRange(1)
grpTop = oshp.Top
If oshp.Type <> msoGroup Then Exit Sub
For i = 1 To oshp.GroupItems.Count
myTop(i) = oshp.GroupItems(i).Top
ReDim Preserve myTop(1 To UBound(myTop) + 1)
Next
ReDim Preserve myTop(1 To UBound(myTop) - 1)
SendKeys "{DOWN}"
DoEvents
If grpTop = oshp.Top Then
For i = 1 To oshp.GroupItems.Count
If oshp.GroupItems(i).Top <> myTop(i) Then
strResult = strResult & oshp.GroupItems(i).Name & vbCrLf
End If
Next
MsgBox "These group shapes were selected:" & vbCrLf & strResult
Else
MsgBox " A group is selected but no group items were selected"
End If
SendKeys "{UP}"
End Sub
Andy Pope
07-23-2012, 03:30 AM
Assuming I have understood the "selection is one or more items in a group" part can you not use ChildShapeRange object?
for each xx in activewindow.Selection.ChildShapeRange:xx.Fill.ForeColor.RGB=255:next xx
John Wilson
07-23-2012, 03:34 AM
You learn something new every time Andy posts!
Cosmo
07-23-2012, 09:52 AM
That looks like it works, Andy! I had seen the 'childShapeRange' in the object model, but hadn't put it together that it would include the shapes selected from the group. I probably should have realized that, but it totally eluded me.
Thanks to both of you; and of course I always have the good questions, John. I feel like I've already been hit by every other 'idiosyncracy' and 'quirk' that Microsoft has 'provided' in PowerPoint's VBA object model. ;)
I appreciate the assistance!
Paul_Hossler
07-23-2012, 11:21 AM
Is there any way to determine which items in a group are selected and which are not?
Maybe I took Cosmo too literally about selecting an item in a group.
Follow on question ...
How can you determine the selected .ChildShapeRange?
If I have a group of 4 shapes and the second child is selected, how can I determine that?
I got this far before getting stuck
Option Explicit
Sub SelectedShape()
Dim i As Long
With ActiveWindow.Selection
If .HasChildShapeRange Then
For i = 1 To .ChildShapeRange.ConnectionSiteCount
MsgBox .ChildShapeRange.Child(i).Type ' does't work
Next I
End If
End With
End Sub
Paul
John Wilson
07-23-2012, 11:50 AM
Assuming the shapes have text
Sub which_ones()
Dim i As Integer
Dim strSel As String
With ActiveWindow.Selection
For i = 1 To .ChildShapeRange.Count
strSel = strSel & .ChildShapeRange(i).TextFrame.TextRange & vbCrLf
Next i
End With
MsgBox "Selected :" & vbCrLf & strSel
End Sub
Paul_Hossler
07-23-2012, 12:29 PM
Got it
I kept coming up with .ChildShapeRange.Count = 1 because I only had one 'sub shape' selected, and I was thinking that the .ChildShapeRange was referring to a collection of all the shapes within the Group.
I missed the implication that .ChildShapeRange would be all of the sub-shapes selected.
Thanks
Paul
Cosmo
07-23-2012, 12:30 PM
Maybe I took Cosmo too literally about selecting an item in a group.
Follow on question ...
How can you determine the selected .ChildShapeRange?
If I have a group of 4 shapes and the second child is selected, how can I determine that?
I got this far before getting stuck
Option Explicit
For i = 1 To .ChildShapeRange.ConnectionSiteCount
Paul
As John pointed out, you're using 'ConnectionSiteCount' (which is the # of places where a connector will 'snap' to: a square has 4; a circle has 8), where you need to use 'Count'
I missed the implication that .ChildShapeRange would be all of the sub-shapes selected.
That was where I was going wrong as well.
Paul_Hossler
07-23-2012, 03:38 PM
Can I blame the on-help?? :doh:
Didn't think so
That .ConnectionSiteCount was about the 5th or 6th thing I tried, after I completely missed the fact that the .Count approach was telling the the correct answer, but I didn't believe it :banghead:
Thanks to all
Paul
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.