View Single Post
 
Old 10-13-2023, 03:21 AM
AllekieF AllekieF is offline Windows 10 Office 2021
Novice
 
Join Date: Oct 2023
Location: Netherlands
Posts: 9
AllekieF is on a distinguished road
Default

Modified the code a bit. Should work, but doesn't check for correct selection type.

Code:
Option Explicit

Sub reziseImage()
Dim pageHeight As Integer, pageWidth As Integer
Dim cropSize As Double

pageHeight = ActivePresentation.PageSetup.SlideHeight
pageWidth = ActivePresentation.PageSetup.SlideWidth

If ActiveWindow.Selection.Type = ppSelectionShapes Then
    Application.CommandBars.ExecuteMso ("PictureResetAndSize")
    With ActiveWindow.Selection.ShapeRange
        .LockAspectRatio = True
        If .Height / .Width > pageHeight / pageWidth Then
            cropSize = (pageWidth / .Width * .Height - pageHeight) / (pageWidth / .Width) / 2
            .Width = pageWidth
            .PictureFormat.CropTop = cropSize
            .PictureFormat.CropBottom = cropSize
        Else
            cropSize = (pageHeight / .Height * .Width - pageWidth) / (pageHeight / .Height) / 2
            .Height = pageHeight
            .PictureFormat.CropLeft = cropSize
            .PictureFormat.CropRight = cropSize
        End If
        .Left = 0
        .Top = 0
    End With
End If
End Sub
Reply With Quote