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!!
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
Alignment example PPT.JPG
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
ETA: This is a cross-post from VBA Express
Bookmarks