我在工作表上有几张图像.我想将它们的大小都调整为相同的大小,但似乎无法正常工作.我以为这就像下面的代码,但这实际上使所有内容都具有不同的大小.
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, but this actually makes everything different sizes.
Sub ChangeAllPics() Dim s As Shape For Each s In ActiveSheet.Shapes s.Select s.Width = 500 s.Height = 200 Next s End Sub推荐答案
我认为您只是错过了一件小事.默认情况下(在测试时),插入工作表的图像具有LockAspectRatio=True.
I think you're only missing a minor thing. By default (when I test it) images inserted to the sheet have LockAspectRatio=True.
您需要将其设置为False,否则更改可能是不可预测的:如果使用 F8 逐步执行代码,则可以观察到Width的更改,但是在下一行Height恢复上一次的宽度更改.
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.
因此,将其设置为false,图像应保留指定的宽度/高度.
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更多推荐
如何调整工作表上所有图像的大小?
发布评论