0
votes

i got the following code which pastes a range from a sheet to same sheet.

  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

I would like to paste the "pastedPic" to a Workbook("masterfile.xlsm").Sheets("Page1") to a range which i select and if this does not work then i would like to specify the cells as i did in my code, but this time in another workbook and another worksheet. The workbook that i want to past is already open.

What should i do ?

1
Understand the code you have and it's cake.findwindow
@YigitTanverdi's see my answer. You basically had it for pasting into a different WorkBookJean-Pierre Oosthuizen

1 Answers

0
votes

You can use

 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