Sub ResizeTable() Dim tbl As ListObject Dim tblRange As Range Dim newHeight As Double Dim newWidth As Double Dim ratio As Double

Set tbl = ActiveSheet.ListObjects('Table1') '替换为你的表格名称

Set tblRange = tbl.Range

newHeight = (Range('L16').Top - Range('L9').Top) * 0.9 '90%高度
newWidth = (Range('N9').Left - Range('L9').Left) * 0.9 '90%宽度

If tblRange.Height > newHeight Then '如果表格高度大于90%
    ratio = newHeight / tblRange.Height
Else
    ratio = newWidth / tblRange.Width '否则按照宽度比例调整大小
End If

tblRange.Height = tblRange.Height * ratio
tblRange.Width = tblRange.Width * ratio

End Sub

Excel VBA 代码:自动调整 L9 到 L16 表格图片大小

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

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