Quote Originally Posted by ajjava View Post
See the attached deck. This is what the finished product should look like. Decks can be up to 350 slides.

The chart/table combos are picture objects that are sometimes placed in random positions on the slide template. Those picture objects need to be aligned with the rectangle shape object on each slide.

My goal is to automate the alignment of the picture objects with the shape objects. I have code that correctly gets the job done...for about 60% of the slides. Something is going awry for the other 40% and I don't know what it is.

Any guidance would be hugely appreciated!!

Here is my objective:

In the finished deck, each slide will have EITHER 2 or 3 shapes:

Title 1 + Picture 2

OR

Title 1 + Picture 2 + Rectangle 2

Constants for 3-shape slides:
  • Every slide will have 3 shapes = ‘Title 1’, ‘Picture 2’, ‘Rectangle 2’
  • Rectangle 2 DOESN'T NEED TO BE POSITIONED WITH THIS MACRO and will ALWAYS be in one of two EXACT positions and one of two EXACT sizes = Tall, slim rectangle on right side of slide

Short, wide rectangle on bottom of slide
Variables:
  • Picture 2 size can vary, but not by much


Need a macro that will:

  • For every slide in presentation
  • IF Rectangle 2 is on the RIGHT SIDE of slide, align Picture 2 with MIDDLE of Rectangle 2 WITHOUT REPOSITIONING RECTANGLE 2
    • I already wrote the code for this piece, cleaned up and perfected by John Wilson. See code snippet below

  • IF Rectangle 2 is at the BOTTOM of the slide, align VERTICAL CENTERS of Rectangle 2 and Picture 2 WITHOUT REPOSITIONING RECTANGLE 2
  • In either scenario, need the macro to put a (somewhat) uniform amount of space between Picture 2 and Rectangle 2

Test Positioning Macro.pptx


Existing code that takes care of the 1st scenario (where Rectangle 2 is on the right side of the slide):

Sub Aligner_MIDDLE() 'This aligns one shape's middle to another shape's middle, WITHOUT repositioning the shapes on the slide  John Wilson cleaned up my code
Dim osl As Slide
Dim osh As Shape
Dim osh1 As Shape
Dim osh2 As Shape


Set osl = ActiveWindow.Selection.SlideRange(1)


For Each osl In ActivePresentation.Slides
        For Each osh In osl.Shapes
        
        If osh.Name = "Rectangle 2" And osh.Height > 100 Then
        Set osh1 = osh
        End If
        
        If osh.Name = "Picture 2" Then
        Set osh2 = osh
        End If
        
        Next osh
        
        If Not osh1 Is Nothing And Not osh2 Is Nothing Then
        osh2.Top = osh1.Top + osh1.Height / 2 - osh2.Height / 2
        
        
        
        End If
        
Next osl


MsgBox "Macro has finished!" & vbCrLf & "", , "Done!"


End Sub
Nice post, your post is really useful for me. Also Its really nice and epic. Thanks a lot for the quality info on this topic.power point course and halpfull thanks..