Sub ResizeImages()

On Error Resume Next 'Ignore errors during loop

Dim sh As Shape 'Define shape object variable

For Each sh In ActiveSheet.Shapes 'Loop through all shapes in active worksheet
    
    If sh.TopLeftCell.Address = '$L$9' Or sh.TopLeftCell.Address = '$L$10' _
    Or sh.TopLeftCell.Address = '$L$11' Or sh.TopLeftCell.Address = '$L$12' _
    Or sh.TopLeftCell.Address = '$L$13' Or sh.TopLeftCell.Address = '$L$14' _
    Or sh.TopLeftCell.Address = '$L$15' Or sh.TopLeftCell.Address = '$L$16' Then 'Check if shape is in specified cells
        
        sh.Height = 87.874015748 'Resize shape to specified height
        sh.Width = 87.874015748 'Resize shape to specified width
        sh.Left = sh.TopLeftCell.Left + (sh.TopLeftCell.Width - sh.Width) / 2 'Reposition shape to center of cell horizontally
        sh.Top = sh.TopLeftCell.Top + (sh.TopLeftCell.Height - sh.Height) / 2 'Reposition shape to center of cell vertically
        sh.LockAspectRatio = msoFalse 'Allow shape to be resized without maintaining aspect ratio
        
    End If
    
Next sh

End Sub

VBA Code to Resize and Reposition Images in Excel Worksheet

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

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