3

i have below vba codes copy existing worksheet data to new worksheet, it's working fine, but it won't copy pictures file (eg.jpg) in worksheet, how can i copy picture file as well? Thank you.

  Set source2 = Worksheets("today").Range("A5:l68")

       Sheets.Add After:=Sheets(Sheets.Count)
    Set dest2 = ActiveWorkbook
    Source2.Copy
      With dest2.Sheets(2)
       .Cells(1).PasteSpecial Paste:=8
       .Cells(1).PasteSpecial Paste:=xlPasteValues
       .Cells(1).PasteSpecial Paste:=xlPasteFormats
       .Cells(1).Select

    Application.CutCopyMode = False

End With
robin
  • 171
  • 1
  • 6
  • 23

2 Answers2

4

I think this question is a duplicate of copy & paste a picture from one sheet to another , regardless you can use the code below...This should paste Pictures to new sht in approx same position as original sheet.

Sub MG15Jun43
Dim pic As Shape, rng As Range
For Each pic In ActiveSheet.Shapes
   If pic.Type = msoPicture Then
     pic.Copy
     With Sheets("Sheet2")
        .Select
        .Range(pic.TopLeftCell.Address).Select
        .Paste
     End With
     Selection.Placement = xlMoveAndSize
   End If
Next pic
End Sub
R Hamilton
  • 263
  • 2
  • 14
  • hi, thanks for your help, yes your code is working, but it copy only shape object, jpeg file not copy, any idea how to copy jpeg file as well? – robin Oct 20 '17 at 16:08
  • ActiveSheet.Shapes.Range(Array("Picture 2")).Select Selection.Copy Sheets("Sheet3").Select ActiveSheet.Paste – R Hamilton Oct 20 '17 at 16:23
  • Works for me. Try commenting out the rest of your code, leaving only those 4 rows and test that way... – R Hamilton Oct 20 '17 at 16:38
  • The line mentioned by @R Hamilton extract the path name of the file. Try debugging your code to find out if the Shape have the .jpeg filename. Sometimes image is attached without .jpeg file location information. –  Oct 20 '17 at 17:49
0

Try using:

Sheets("today").Copy After:=Sheets(Sheets.Count)
  • hi this code copy entire worksheet, but i want to copy certain cell range only. anyway thanks for your help. – robin Oct 20 '17 at 16:09