用vba粘贴指定范围的图片

我有以下代码。 我想粘贴这个复制的图片到我在Destinationsheet中select的范围。 不过,我只知道如何通过select.top,.left,.width,.height设置位置。 有没有办法将这个图片粘贴在一个选定的范围内,如G30:J:30?

Windows(osman).Activate Sheets("Overview").Range("A30:D37").CopyPicture Dim DestinationSheet As Worksheet Set DestinationSheet = Workbooks(anan).Sheets("Eingabefeld") DestinationSheet.Paste Dim pastedPic As Shape Set pastedPic = DestinationSheet.Shapes(1) With pastedPic .Top = DestinationSheet.Cells(17, 2).Top 'Rest of positioning code here End With 

我testing了这个,它为我工作。 如果你有一个多单元范围对象,你可以得到宽度和高度。 如果你不改变.LockAspectRatio = msoFalse,你的照片可能会自行调整。

 Dim r As Range Set r = Me.Range("G30:J30") With pastedPic .LockAspectRatio = msoFalse .Top = r.Top .Left = r.Left .Width = r.Width .Height = r.Height End With 

我试过你的代码,这是我想出了。 对于复制图片行,我实际上复制单元格的图片而不是这些单元格内的特定图片。 这是你所期望的吗?

另一个变化是我用ThisWorkbook而不是你的工作簿索引。 根据需要调整

 Sub test() Dim pastedPic As Shape Dim DestinationSheet As Worksheet Dim desitinationRange As Range Set DestinationSheet = ThisWorkbook.Sheets("Eingabefeld") Sheets("Overview").Range("A30:D37").CopyPicture DestinationSheet.Paste Set pastedPic = DestinationSheet.Shapes(1) Set desitinationRange = Me.Range("G30:J30") With pastedPic .LockAspectRatio = msoFalse .Top = desitinationRange.Top .Left = desitinationRange.Left .Width = desitinationRange.Width .Height = desitinationRange.Height End With End Sub