这是我的代码。我想将图片粘贴到特定范围内,我尝试了不同的代码但失败了。我希望它在左上角,或者在" A1"。
中开始 Sub CommandButton2_Click()
ThisWorkbook.Sheets(3).Activate
ThisWorkbook.Sheets(3).Range("B5:G32").Select
Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
Sheet10.Pictures.Paste.Select
ThisWorkbook.Sheets(1).Activate
End Sub
答案 0 :(得分:1)
作为建议,请始终尽量远离Activate
,Select
和Selection
,而应使用引用的对象。
以下代码会将范围(" B5:G32")从Sheets(3)
复制到Sheets(1)
,并将图片放在单元格A1(左上角位置)。< / p>
Private Sub CommandButton2_Click()
ThisWorkbook.Sheets(3).Range("B5:G32").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
With Sheet10.Pictures.Paste
.Left = Range("A1").Left ' <-- setting the left postion to Cell A1
.Top = Range("A1").Top ' <-- setting the top postion to Cell A1
End With
End Sub
答案 1 :(得分:0)
这应该这样做
Sub CommandButton2_Click()
ThisWorkbook.Sheets(3).Activate
Range("B5:G32").Copy 'you can copy directly, in one instruction
ThisWorkbook.Sheets(10).Activate
Range("A1").Select 'select where you want to paste it
ActiveSheet.Pictures.Paste
ThisWorkbook.Sheets(1).Activate
End Sub
检查粘贴为图像的工作示例