2
votes

I get Run-time error '1004' when trying to copy a range of cells and doing a paste as a picture.

Description of the Excel file:

I have 1 Excel file that has 2 sheets:

  • Sheet1 - it has a table with data
  • Sheet2 - it has a Pivot Table that reads the data from the table in Sheet1

(I created this small Excel only for replication purposes as I have the issue in a much bigger Excel file.)

Description of the issue:

I have a macro to copy the range of cells that contains the Pivot Table and paste it as a picture.

The macro is running correctly with no errors in my laptop and in other colleagues' laptops. Some colleagues are getting the error in their laptops.

We all are using:

  • Windows 7 Ultimate 64 bits
  • Office 365 ProPlus (Excel 2016)

Macro created:

Sub Macro4()

Dim ws As Worksheet

Set ws = Sheets("CS - Pivot Tables")

With ws
    .Activate
    .Range("B2:D13").Copy
    .Range("L2").Select
    .Pictures.Paste
End With

Application.CutCopyMode = False

Range("A1").Select

End Sub

***** the macro stops on .Pictures.Paste

2

2 Answers

2
votes

You need to use a different copy to copy pictures:

Sub Macro4()

Dim ws As Worksheet

Set ws = Sheets("CS - Pivot Tables")

    With ws
        .Activate
        .Range("B2:D13").CopyPicture Appearance:=xlScreen, Format:=xlPicture
        .Range("B1").Select
        .Paste
    End With


Range("A1").Select

End Sub
1
votes

Can you try something like this:

Sub Macro4()

    Dim ws      As Worksheet
    dim pic     as picture

    Set ws = Sheets("CS - Pivot Tables")
    With ws 
        .Activate 
        .Range("B2:D13").Copy 
        .Range("L2").Select 
        set pic = .pictures.paste
    End With

    Application.CutCopyMode = False

    Range("A1").Select

End Sub

(Your code is not formatted, but I am guessing I did it right).