Results 1 to 3 of 3

Thread: Grouping shapes using macro in PowerPoint VBA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2019

    Grouping shapes using macro in PowerPoint VBA

    Hello all,

    I have been hustling to automate the task of grouping set of shapes present in slides without using selection. I tried following code. But, the problem is I have to select each shape set( 1 and 2 separately) to group items within those shapes.Is there any possibility to avoid the selection of each shape?

    Would it be efficient to select all the shapes in a slide and then run code(If I do so with following code, shapes are grouped as a whole, I would like to group them individually i.e. If we reposition set 1 , set 2 should not be effected) or any other approach?

    Set 1 refers to yellow rectangle + blue oval + textbox Set 2 refers to two green boxes( lower, upper)

    Sub Grouping()
    End Sub
    Attached Images Attached Images  
    Last edited by CuriosityBug; Aug 12th, 2019 at 12:11 PM.

  2. #2
    Join Date
    Dec 2004

    Re: Grouping shapes using macro in PowerPoint VBA

    you can add shapes to a shaperange, by the name of the shape or some other criteria (eg position), without selecting them
    i have never tried working with multiple shaperanges, you would need to be able to identify each group

    set sr = shaperange
    for each sh in shapes
        if sh.top < 220 then sr.shapes.add sh
    this is totally untested and may be different to working with shapes in other applications
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2019

    Re: Grouping shapes using macro in PowerPoint VBA


    Thank you for the insight. This made me to do some brainstorming. An approach where the code checks for condition of shapes that intersect, touch each other and group elements that satisfy the condition(i.e the lower and upper rectangles touch each other, so they can be grouped and similarly set 1, where shapes are within rectangle) I am not sure, if this is achievable or how it can be done. Please help me!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width