Consulting

Results 1 to 3 of 3

Thread: Need macro for selecting images in all slides and centering them

  1. #1
    VBAX Newbie
    Joined
    Jan 2023
    Posts
    2
    Location

    Question Need macro for selecting images in all slides and centering them

    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

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    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
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Jan 2023
    Posts
    2
    Location
    Thank you so very much you're a lifesaver !!! Much appreciated.

Posting Permissions

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