0

I have a library of eight images on my PowerPoint slide. Based on a userform input, some of the components get duplicated and renamed by adding a "1" or "2" after the original image's name so that they are differentiable. I then want to group the new images (I am building up an item from the component images). I am able to duplicate the images and line them up correctly, but I am having trouble grouping them. Note that I am not always grouping the same number of items, it is dependent on user inputs.

I receive the error "Shape (unknown member): Invalid request. To select a shape, its view must be active."

I searched and attempted to implement several strategies from the help forums but am coming up empty.

PLEASE HELP!!! -Kevin

Part of code below because it is very long, but this is where my first problem arises:

Dim Cargo As Shape, Cargo_Dup as Shape, Chemical as Shape, Chemical_Dup as Shape
Set Cargo = ActivePresentation.Slides(2).Shapes("Cargo")
Set Chemical = ActivePresentation.Slides(2).Shapes("Chemical")
Cargo.Name = "Cargo"
Chemical.Name = "Chemical"

With ActivePresentation
Set Cargo_Dup = ActivePresentation.Slides(2).Shapes("Cargo")
    With Cargo_Dup.Duplicate
        .Name = "Cargo_1st"
        .Left = 0
        .Top = 540
    End With
'CHEMICAL
If Input1 = "Chemical" Then
    Set Chemical_Dup = ActivePresentation.Slides(2).Shapes("Chemical")
        With Chemical_Dup.Duplicate
            .Name = "Chemical" & 1
            .Left = 36.74352
            .Top = 540 + 0.36
        End With
   '''''WHERE PROBLEM ARISES'''''
    ActivePresentation.Slides(2).Shapes("Cargo_1st").Select
    ActivePresentation.Slides(2).Shapes("Chemical1").Select msoFalse
    Set Vehicle = ActiveWindow.Selection.ShapeRange.Group
    Vehicle.Name = "Vehicle"
'Elseif with a bunch for options where addition grouping occurs
KevinJ25
  • 3
  • 2

1 Answers1

1

I need some kind of keyboard macro to type this for me:

Never select anything unless you absolutely have to. You nearly never absolutely have to.

You're asking how to make a view active so that you can select something. I figure that's the wrong question.
It's more useful to know how to work with shapes WITHOUT having to select them. Grouping shapes w/o selecting them is a bit tricky, but it can be done.

Here's an example of how you might go about this:

Sub GroupWithoutSelecting()

    Dim oSl As Slide
    Dim oSh As Shape
    Dim aShapes() As String

    Set oSl = ActivePresentation.Slides(2) ' or whichever slide you like
    ReDim aShapes(1 To 1)

    With oSl
        For Each oSh In .Shapes
            If oSh.Type <> msoPlaceholder Then ' can't group placeholders

                ' Substitute the real condition you want to use
                ' for selecting shapes to be grouped here
                If oSh.Type = msoAutoShape Then
                    ' add it to the array
                    aShapes(UBound(aShapes)) = oSh.Name
                    ReDim Preserve aShapes(1 To UBound(aShapes) + 1)
                End If

            End If
        Next

        ' eliminate the last (empty) element in the array
        ReDim Preserve aShapes(1 To UBound(aShapes) - 1)

        ' Create a shaperange from the array members and group the shaperange
        .Shapes.Range(aShapes).Group

    End With ' oSl

End Sub
Steve Rindsberg
  • 14,442
  • 1
  • 29
  • 34
  • I don't understand your comment of " 'Substitute the real condition you want to use for selecting shapes to be grouped here. " I'm not sure how I would apply what I need to do here. "Cargo_1st" will always be grouped, but then it might be "Chemical1" or "Other1", all depending on what the user inputs to what shapes to duplicate. I want to be able to group the new item duplicated in the "If Input1 = "Chemical" Then" and the "ElseIF" blocks. – KevinJ25 Dec 05 '14 at 22:17
  • Since you haven't explained the logic behind what gets grouped, I can't offer the correct code, but, for example, you could build an array of strings with each element containing the name of one of the shapes to be grouped, then instead of If oSh.Type = msoAutoShape substitute a call to a function that tests whether oSh.Name is also a member of the array. – Steve Rindsberg Dec 06 '14 at 17:54
  • After some work and adding in some redundant input checking lines I was able to get the grouping to work! It seems a little round-about, but it works and is functional so I'm okay with that. I was also able to figure out how to name my new group as well. THANKS!! – KevinJ25 Dec 06 '14 at 19:18