我复制了这张照片。如何使用VBA将此图片调整为单元格大小?
答案 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