Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将复制的范围粘贴到其他工作簿工作表_Vba_Excel - Fatal编程技术网

Vba 将复制的范围粘贴到其他工作簿工作表

Vba 将复制的范围粘贴到其他工作簿工作表,vba,excel,Vba,Excel,我得到了下面的代码,它将一个范围从一张纸粘贴到同一张纸 Sub copyPic() Dim targetSheet As Worksheet Set targetSheet = Sheets("Sheet1") With targetSheet .Range("A1:B10") .CopyPicture .Paste Selection.Name = "pastedPic" With .Shapes("pastedPic") .Top =

我得到了下面的代码,它将一个范围从一张纸粘贴到同一张纸

  Sub copyPic()
Dim targetSheet As Worksheet
Set targetSheet = Sheets("Sheet1")

With targetSheet
    .Range("A1:B10") .CopyPicture
    .Paste
    Selection.Name = "pastedPic"

    With .Shapes("pastedPic")
        .Top = targetSheet.Cells(5, 5).Top
        .Left = targetSheet.Cells(5, 5).Left
        .Width = 50
        .Height = 50

    End With
End With

End Sub
我想将“pastedPic”粘贴到工作簿(“masterfile.xlsm”).Sheets(“Page1”)中,粘贴到我选择的范围内,如果这不起作用,那么我想像在代码中那样指定单元格,但这次是在另一个工作簿和另一个工作表中。我要删除的工作簿已打开

我该怎么办?

您可以使用

 Sheets("Sheet1").Range("A1:B10").CopyPicture
 Dim DestinationSheet as Worksheet
 Set DestinationSheet = WorkBooks("masterfile.xlsm").Sheets ("Sheet1")

 DestinationSheet.Paste 

 Dim pastedPic as Shape

 'The newest picture/shape will always have the index 1

 Set pastedPic = DestinationSheet.Shapes(1)

 With pastedPic 
      .Top = Destination Sheet.Cells(5,5).Top
      'Rest of positioning  code here

 End With

理解你的代码,它就是蛋糕。@YigitTanverdi来看看我的答案。基本上,您可以将其粘贴到不同的
工作簿中
感谢您的回复!如果我想将其粘贴到选择的范围,比如说,如果我想将复制的零件粘贴到“主文件”中的A1:F20,该怎么办?