How to copy and paste as image with VBA?

Asked

Viewed 4,263 times

3

I need to copy a chart and paste it as an image in the same spreadsheet.

I’m trying to select the range that contemplates all the graphic and paste special as file Bitmap or Enchanced. Follows code:

    Range("AM18:BE22").Select
     Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy

    With Sheets("Relatório").Range("CV18:DM22")
    .PasteSpecial DataType:=wdPasteMetafilePicture

    End With

And the error occurs 1004, Erro de definição de aplicação ou objeto.

Anyone can help?

1 answer

1

Try this code, in this case it will copy the index chart 1. If there are more charts, change the index number of ChartObjects.

The Copypicture method will be used, it occurs that you need to copy the graphic object and not the range it is inserted.

Planilha1.ChartObjects(1).Chart.CopyPicture
Planilha2.Paste Planilha2.Range("CV18:DM22")

To declare which spreadsheet is being used, change the values of Planilha1 and Planilha2. If you have difficulties, please refer to this link.

  • Thank you Daniel. I’ll try it here. .

  • Do you want to copy the Range with the values of the cells? This will depend on many variables and can be performed in numerous ways.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.