如何将图片调整到单元格的大小?

时间:2014-04-17 22:26:38

标签: image excel vba

我复制了这张照片。如何使用VBA将此图片调整为单元格大小?

1 个答案:

答案 0 :(得分:1)

使用此代码(与this相关的Q):

Sub copy()
    Dim sh As Shape, ws1 As Worksheet, ws2 As Worksheet

    Set ws1 = Worksheets("mechanic")
    Set ws2 = Worksheets("character")

    ws1.Shapes("Picture").copy
    With ws2.Range("A8").MergeArea
        .PasteSpecial
        Set sh = ws2.Shapes(ws2.Shapes.Count) 'get last shape, i.e. pasted picture
        If .Height / sh.Height < .Width / sh.Width Then
            sh.ScaleHeight .Height / sh.Height, msoFalse
        Else
            sh.ScaleWidth .Width / sh.Width, msoFalse
        End If
    End With
End Sub