Home > Mobile >  VBA cannot scale images from ppt handout files with apsect ratio, i need to get image Scalewidth sca
VBA cannot scale images from ppt handout files with apsect ratio, i need to get image Scalewidth sca

Time:09-07

this is for hundreds of students, pls help.

in VBA how to get the Images Height or width scaling factor. for example they width, and set the Height to the same scaling factor. the reason i ask i normal such a code as this would scale with lock apsect ratio

but every time i produce handout in powerpoint i get very small images, Everybody doing studies know what i am talking about. so i use a macro to resize the picture, no bigi, but these handout generated images does not scale with "lock aspect ratio" even if you use the code ".LockAspectRatio = msoTrue"

no matter what i do it cannot work so know i want to scale the height my self.

so after i scale the width to 18.46 cm, i want to get the scaleWidth, and set the ScaleHeight to the same number. Fx. if scaleWidth end up being 145 %, then get this number and set ScaleHeight to the same number.

i am simply not able to find a solution to get scaleHeigth, and the guide to get Height pixel/inches is not something i am able to execute in my doc at all.

Sub Resize_All_Images()
'
' Resize all pictures to that corresponding size
'
'
With ActiveDocument
For I = 1 To .InlineShapes.Count
    With .InlineShapes(I)
    'the width that it will resize to'
    .Width = CentimetersToPoints(18.46)
    End With
Next I
End With
End Sub

regards

CodePudding user response:

Try this:

Sub Resize_All_Images()
    '
    ' Resize all pictures to that corresponding size
    '
    '
    Dim NewWidth As Long: NewWidth = CentimetersToPoints(18.46)
    Dim ils As InlineShape
    With ActiveDocument
        For Each ils In .InlineShapes
            With ils
                'the width that it will resize to'
                .Height = (.Height / .Width) * NewWidth
                .Width = NewWidth
                .LockAspectRatio = msoTrue
            End With
        Next ils
    End With
End Sub
  • Related