VBA Macro: Resize and Center Shapes in Specific Cells
Sub ResizeShapes()
Dim shp As Shape
For Each shp In ActiveSheet.Shapes
shp.LockAspectRatio = msoFalse 'Unlock aspect ratio
If shp.TopLeftCell.Address >= '$L$9' And shp.BottomRightCell.Address <= '$L$16' Then 'If shape is in cells L9 to L16
shp.Height = 87.874015748 'Resize height
shp.Width = 87.874015748 'Resize width
shp.Top = shp.TopLeftCell.Top + (shp.TopLeftCell.Height - shp.Height) / 2 'Reposition to center of cell
shp.Left = shp.TopLeftCell.Left + (shp.TopLeftCell.Width - shp.Width) / 2 'Reposition to center of cell
End If
Next shp
End Sub
原文地址: https://www.cveoy.top/t/topic/mAG4 著作权归作者所有。请勿转载和采集!