4

Currently I am trying to scale a picture in VBA, but cannot seem to get what I need. Every time I run though....

ActiveSheet.Pictures.Insert("C:\\\Logo.bmp").Select
            With Selection
                  .ShapeRange.ScaleWidth 1.4, msoTrue
                  .ShapeRange.ScaleHeight 0.5, msoFalse
             End With 

It will scale to the correct width initially, but then when I go to the next line and try to scale the height it changes the width. Can someone help me understand why this happens and suggest a better way of scaling the picture. I need it to be about 125% bigger in length and about 50% smaller in height.

Thanks so much.

4

2 回答 2

6

Include this line:

.ShapeRange.LockAspectRatio = msoFalse

To allow both width and height being "unlocked", put it right on the top.

With Selection
    .ShapeRange.LockAspectRatio = msoFalse
    .ShapeRange.ScaleWidth 1.4, msoTrue
    .ShapeRange.ScaleHeight 0.5, msoFalse
End With
于 2013-08-15T17:29:44.857 回答
-1

In the ShapeRange.ScaleWidth and ScaleHeight methods, the RelativeToOriginalSize argument should be msoFalse if you want to scale it relatively (as in maintain aspect ratio, it will adjust width and height while scaling). So if you don't want it to scale relatively, just set that argument to msoTrue for both:

ActiveSheet.Pictures.Insert("C:\\\Logo.bmp").Select
With Selection
    .ShapeRange.ScaleWidth 1.4, msoTrue
    .ShapeRange.ScaleHeight 0.5, msoTrue
End With
于 2013-08-15T17:26:51.350 回答