Question : How do you group PowerPoint Objects on a slide

I have an Excel file with a map of object names, slide number and grouping ID.
From excel, i populate a powerpoint template with certain data tables, text boxes, etc. I then want to group certain objects according to the mapping in the excel template.

It groups the first object easily enough but then I get the following error on the second grouping.

-2147188160 Shape.Select : Invalid Request. To select a shape, it's view must be active.

I assume that i need to select the new slide or something, but not sure what.

Below is my code.

any help or suggestions is greatly appreciated.

Thanks...
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
Sub GroupObject()
    
On Error GoTo errHandler:

Dim ShapeList() As String
Dim oShape As Shape
Dim count As Long
Dim rngGroup As Range
Dim strObjName As String
Dim strSlideNum As Long

Set rngGroup = ThisWorkbook.Sheets(SHEETCONFIG).Range("nrGroupStart")
strObjName = rngGroup.Offset(0, 2).Value
strSlideNum = rngGroup.Offset(0, 3).Value

Do While rngGroup <> ""

count = 0
    Do
        count = count + 1
        ReDim Preserve ShapeList(1 To count)
        ShapeList(count) = oPPTFile.Slides(strSlideNum).Shapes(strObjName).Name
    
    Debug.Print strSlideNum&; " " & strObjName & " " & count
    Set rngGroup = rngGroup.Offset(1, 0)
    
    If rngGroup.Offset(0, 1) <> rngGroup.Offset(-1, 1) Then Exit Do
    
        strObjName = rngGroup.Offset(0, 2).Value
        strSlideNum = rngGroup.Offset(0, 3).Value

    Loop Until rngGroup.Offset(0, 1) <> rngGroup.Offset(-1, 1)

oPPTFile.Slides(strSlideNum).Shapes.Range(ShapeList()).Group.Select
        strObjName = rngGroup.Offset(0, 2).Value
        strSlideNum = rngGroup.Offset(0, 3).Value
Loop

Exit Sub

errHandler:
MsgBox Err.Number & Err.Description

End Sub

Answer : How do you group PowerPoint Objects on a slide

You cannot select a shape if the slide it's on is not selected or active.

As rorya says though there's no need to select the group in your example.

oPPTFile.Slides(strSlideNum).Shapes.Range(ShapeList()).Group would be fine.

It's a good rule in PowerPoint to try to never select anything in code, it's very rarely necessary.
Random Solutions  
 
programming4us programming4us