PDA

View Full Version : [SOLVED:] Need macro for selecting images in all slides and centering them



Visoredz
01-28-2023, 10:50 AM
Hello!

I would be very thankful if someone could kindly provide me with the code for selecting all images in all slides and centering them vertically and horizontally.
There is 1 image per slide.

I have been exporting alot of images into powerpoint and for some reason they are being imported off-center. Manually centering each one would be hell.

Help would be greatly appreciated !!! Thank you :)

John Wilson
01-29-2023, 02:10 PM
This should do it

Sub center_image()
Dim osld As Slide
Dim oshp As Shape
Dim SW As Long
Dim SH As Long
SW = ActivePresentation.PageSetup.SlideWidth
SH = ActivePresentation.PageSetup.SlideHeight
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If isPic(oshp) Then
oshp.Left = SW / 2 - oshp.Width / 2
oshp.Top = SH / 2 - oshp.Height / 2
End If
Next oshp
Next osld
End Sub


Function isPic(oshp As Shape) As Boolean
If oshp.Type = msoPicture Then isPic = True
If oshp.Type = msoPlaceholder Then
If oshp.PlaceholderFormat.ContainedType = msoPicture Then
isPic = True
End If
End If
End Function

Visoredz
01-30-2023, 02:30 AM
Thank you so very much you're a lifesaver !!! Much appreciated.