1
votes

I am having some difficulty using the .Group method on a ShapeRange.

For example, I am not able to Group a table with a textbox, nor am I able to group the slide's title shape with a textbox, etc. I notice that Powerpoint does not allow you to Group certain shapes together, as the "Group" option is disabled on the context menu:

Group is disabled for some shapes

I try the following in VBA, which predictably fails:

Sub TestGroupShapes()

    Dim sld As slide
    Dim tb As Shape
    Dim tb2 As Shape
    Dim tbl As Shape

    Set sld = ActivePresentation.Slides(1)
    Set tbl = sld.Shapes.AddTable(3, 3, 100, 100, 100, 100)
    tbl.Name = "Table"
    Set tb = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 200, 200, 50, 50)
    tb.Fill.Visible = msoCTrue
    tb.Name = "TextBox1"
    Set tb2 = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 300, 300, 50, 50)
    tb2.Fill.Visible = msoCTrue
    tb2.Name = "TextBox2"

    '## This works. I am able to group two textbox shapes together:
    sld.Shapes.Range(Array(tb2.Name, tb.Name)).Group

    '## This fails, I am not able to group a shape with a Table
    '   Also fails, e.g., if I try to group with the slide's Title shape, etc.
    sld.Shapes.Range(Array(tbl.Name, tb.Name)).Group


End Sub

Are there any other methods I might use to "tie" certain shapes together?

Update 5/25/2013

The problem is that shapes which a user might copy (Ctrl+V/etc) retain the same .Name as the original shape. The application I am developing assigns unique IDs to shapes that it creates, but these IDs will not remain unique if the user copies them. For example, some user might "copy" an existing textbox, instead of inserting a new textbox.

Since the application is required to maintain and update the shapes (tables, textboxes, charts, etc), any shape(s) created by "copying" an existing shape can potentially cause problems, since my application will no longer be able to determine which shapes to update, remove, etc.

What I was hoping to do is Group them together. Although it's not failsafe (the user could still manually Ungroup them, but I felt like that would be at least an additional safegaurd.

3
I like your question... unfortunately I think it's not feasible to group tables :(Kazimierz Jawor
I'm discovering that :) I find it curious that it is not possible to group tables, and other shapes, or that certain shapes are prevented from this method, but I can't find documentation about which shapes cannot be grouped, or why they cannot be grouped :(David Zemens

3 Answers

1
votes

It is not possible to group some shapes to one shape. But you can use ShapeRange to tie different types of shapes together. Then some properties can be set on the shape-range it self, another on particular item. HTH

Sub test()

    Dim tableShape As Shape
    Dim textboxShape1 As Shape
    Dim textboxShape2 As Shape
    Dim myShapeRange As ShapeRange

    With ActivePresentation.Slides(1)
        Set tableShape = .Shapes.AddTable(3, 3, 100, 100, 100, 100)
        tableShape.Name = "Table"

        Set textboxShape1 = .Shapes.AddTextbox(msoTextOrientationHorizontal, 200, 200, 50, 50)
        textboxShape1.Name = "TextBox1"

        Set textboxShape2 = .Shapes.AddTextbox(msoTextOrientationHorizontal, 300, 300, 50, 50)
        textboxShape2.Name = "TextBox2"

        Set myShapeRange = .Shapes.Range(Array("Table", "TextBox1", "TextBox2"))
    End With

    Call FormatShapes(myShapeRange)

End Sub

Private Sub FormatShapes(inputShapeRange As ShapeRange)
    Dim shapeItem As Shape

    With inputShapeRange
        .Align msoAlignLefts, msoFalse
        .AlternativeText = "My group 123"
    End With

    For Each shapeItem In inputShapeRange
        With shapeItem
            .Fill.Visible = msoTrue
            .Fill.Solid
            .Fill.ForeColor.RGB = RGB(255, 0, 0)
            .Fill.TwoColorGradient msoGradientHorizontal, 1
        End With
    Next shapeItem
End Sub
1
votes

When ever you are not able to group your items there is some sort of glitch going on. Follow the steps below to "reactivate the group feature." See if this helps you:

  1. Add a new slide to your presentation (you can delete it later)
  2. Insert three shapes of three different colors
  3. Arrange the shapes to attempt to group (the group feature should return)
  4. If it does not return, a temporary fix is to right click on your 3 selected items, then choose the "picture" Paste option (looks like clip board and picture icon together) this should group the items together as well.

Hope this helps!

0
votes

Here is a long-way to do it, but it'll work (at least it did for me, :D).

What you'll have to do is make your tables then right click on them separately; what you want to do is save your tables as a picture (as a JPEG will work great for this) either to your desktop or some other convenient file. Then put your tables (in picture form) back into the slide. You should be able to group all your things together now.

It is a PITA, but at least it'll work. Best of luck!