Excel VBA 调整图片高度宽度等于单元格高度宽度

2019-04-15 13:33发布

'调整图片高度宽度等于单元格高宽
Sub setpic()
Dim Pic As Shape
    For Each Pic In ActiveSheet.Shapes
     If Pic.Type = 13 Then '如果pic的类型是图片
        Pic.LockAspectRatio = msoFalse
        Pic.Top = Pic.TopLeftCell.Top
        Pic.Left = Pic.TopLeftCell.Left
        Pic.Height = Pic.TopLeftCell.Height
        Pic.Width = Pic.TopLeftCell.Width
     End If
    Next
End Sub
Sub setpic1()
Dim p As Shape, D$
  For Each p In ActiveSheet.Shapes
    p.LockAspectRatio = msoFalse
    D = p.TopLeftCell.Address
    p.Height = Range(D).Height
    p.Width = Range(D).Width
    p.Top = Range(D).Top
    p.Left = Range(D).Left
  Next
End Sub