在VBA和Excel中复制粘贴随机范围的图片

这是我的代码。 我想粘贴在特定范围的图片,我尝试了不同的代码,但失败了。 我想把它放在左上angular,或者在“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 

作为一个build议,总是尽量远离ActivateSelectSelection ,而不是使用引用的对象。

下面的代码将从Sheets(3)复制范围(“B5:G32”)到Sheets(1) ,并将图片放置在单元格A1(左上angular位置)。

 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 

这应该做到这一点

  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 

检查一个工作示例粘贴为图片在这里http://s000.tinyupload.com/?file_id=04177936342289971269