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:
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.