dcsimg
Results 1 to 4 of 4

Thread: Grouping shapes using macro in PowerPoint VBA

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2019
    Posts
    31

    Grouping shapes using macro in PowerPoint VBA

    Hello,


    I am trying to group multiple shapes in a slide without using selection. Following is snippet I am working on but the problem is, each time I have to select shapes that are to be grouped and then run macro which is similar to manually grouping by using builtin feature.

    My idea is to 1. select all ( ctr+ A) and run macro or
    2. To detect shapes that needs to be grouped and collect them into range or array and then utilize grouping method.
    To detect shapes - A condition that checks for overlapping or touching of shapes and consider them as shapes that are to be grouped.
    I am not sure how can this be done. Any thoughts on this is really helpful.

    code:

    Sub Grouping() ActiveWindow.Selection.ShapeRange.Group
    ' A code which can avoid task of selecting shapes
    End Sub
    Attached Images Attached Images  
    Last edited by CuriosityBug; Aug 23rd, 2019 at 05:16 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,628

    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

    Code:
    set sr = shaperange
    for each sh in shapes
        if sh.top < 220 then sr.shapes.add sh
    next
    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
    pete

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2019
    Posts
    31

    Re: Grouping shapes using macro in PowerPoint VBA

    Hello,

    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!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2019
    Posts
    31

    Re: Grouping shapes using macro in PowerPoint VBA

    Hello,

    I found few online resources that can help one approach. I am trying to use overlap shape function instead of intersect function (as PowerPoint doesn't support this function). Please help!
    https://www.thespreadsheetguru.com/t...ction-of-cells - main sub procedure
    https://stackoverflow.com/questions/...owerpoint-2007 - shape overlap function

    Note : Edited the question for better understanding

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width