如何调整工作表上所有图像的大小? [英] How to resize all images on a worksheet?

查看:85
本文介绍了如何调整工作表上所有图像的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作表上有几张图像.我想将它们的大小都调整为相同的大小,但似乎无法正常工作.我以为这就像下面的代码,但这实际上使所有内容都具有不同的大小.

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

这篇关于如何调整工作表上所有图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆