This is driving me crazy. It seems so easy, but I am obviously missing something. I have a macro that lets the user select one or more photos, provide a caption, and then it is supposed to groups the photos, put the caption under the group, then group the caption with the grouped photos, so they can all be moved as one unit.
Everything works fine until the very last line of the macro. It gives me an error saying "grouping is disabled for the selected shapes."
Sub captionselectedphoto(control As IRibbonControl)Dim shapesselected As IntegerDim photos2caption As ShapeRangeDim phototitle As Stringshapesselected = Selection.ShapeRange.countIf shapesselected = 0 Then MsgBox "Please select one or more photos to caption, then try again" Exit SubEnd IfSet photos2caption = Selection.ShapeRangeIf photos2caption.count > 1 Then photos2caption.GroupApplication.ScreenRefreshphototitle = InputBox("Photo title?")Selection.InsertCaption Label:="Figure", TitleAutoText:="", _ Title:=": " & phototitle, Position:=wdCaptionPositionBelow, ExcludeLabel:=0Set captionbox = ActiveDocument.Shapes(ActiveDocument.Shapes.count)MsgBox photos2caption.Name 'returns "Group 20"MsgBox captionbox.Name 'returns "Text Box 9"ActiveDocument.Shapes.Range(Array(photos2caption.Name, captionbox.Name)).GroupEnd Sub
As you can see, I stuck in a couple msgboxes near the end to tell me the shape names. The return the expected names. What is most maddening is that I can run this test macro and it does exactly what I want:
after the 2 message boxes (& commented out the message boxes) but before attempting to group.
The code fails, press End. Go to immediate window and run the debug.print line and it still fails.
Now, select the caption box so the border is solid and run the debug.print line a 2nd time and the grouping fails again.
Now, instead, select the already grouped images BUT NOT the caption box and the grouping works. (incidentally it also works if the caption box is selected....)