以下是将 L9 到 L16 的表格图片自动调整大小的 VBA 代码:

Sub ResizePictures()
    Dim ws As Worksheet
    Dim shp As Shape
    Set ws = ActiveSheet
    For Each shp In ws.Shapes
        If shp.Type = msoPicture Then
            If shp.TopLeftCell.Row >= 9 And shp.BottomRightCell.Row <= 16 And shp.Type = msoPicture Then
                shp.LockAspectRatio = msoFalse
                shp.Width = shp.TopLeftCell.Width
                shp.Height = shp.TopLeftCell.Height
            End If
        End If
    Next shp
End Sub

将此代码复制并粘贴到 VBA 编辑器中,然后运行它即可。它将遍历工作表上的所有形状,并将尺寸调整为其所在单元格的大小,前提是它们位于 L9 到 L16 行之间。请注意,此代码假定所有 L9 到 L16 之间的形状都是图片。如果存在其他形状,如文本框或图表,请相应地进行修改。


原文地址: https://www.cveoy.top/t/topic/mALP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录