How to resize all images on a worksheet?

前端 未结 2 1704
孤独总比滥情好
孤独总比滥情好 2021-01-24 02:29

I have several images on a worksheet. I want to resize them all to the same size, but I can\'t seem to get it working quite right. I thought it would be like the code below, b

2条回答
  •  一整个雨季
    2021-01-24 02:58

    I think you're only missing a minor thing. By default (when I test it) images inserted to the sheet have LockAspectRatio=True.

    You need to set this to False, otherwise the changes may be unpredictable: if you step through the code using F8 you can observe that Width changes, but then on the next line Height reverts the width change from previous.

    So, set this to false and the images should retain the specified width/height.

    Option Explicit
    Sub ChangeAllPics()
    Dim s As Shape
    Dim ws As Worksheet
    Set ws = ActiveSheet
    
    For Each s In ActiveSheet.Shapes
        s.LockAspectRatio = msoFalse
        s.Width = 500
        s.Height = 200
    
    Next s
    End Sub
    

提交回复
热议问题