kohigany
kohigany

Reputation: 3

Copy / Paste from other workbooks

I wrote code to copy and paste to my workbook the used ranges from other workbooks. In my computer it works but when I send to anyone the paste process results in an error message:

"This image cannot currently be displayed."

enter image description here

The currently version, I used xlPasteAll:

Workbooks(fl.Name).Worksheets(sheetindex).Range("A2:P" & Lastrow).Copy
Workbooks(fl.Name).Close
Worksheets(sheetindex).Activate
ActiveSheet.Range(Cells(startrow,1),Cells(rangeCount,16)).PasteSpecial xlPasteAll

Upvotes: 0

Views: 380

Answers (2)

therak
therak

Reputation: 301

You might want to have a look at this KB-Article. It describes an error which occurs with images from other workbooks while copying a sheet or range into an other workbook.

Had a similar problem - we copied a sheet with images into the target workbook. If you close the source workbook before you save and close the target workbook this error would occur. If you left the source workbook open and closed the target workbook, the image was shown correctly (Close source workbook afterwards and reopen the target workbook manually).

The KB-Article/Hoftix was able to fix our problem - it would also explain why it works on your Workstation and not somewhere else. (Different office patches...)

Upvotes: 1

PASUMPON V N
PASUMPON V N

Reputation: 1186

You are closing the sheet after copy the values. use close command after pasting the values

  Sub test()

    Workbooks(fl.Name).Worksheets(sheetindex).Range("A2:P" & Lastrow).Copy
    Worksheets(sheetindex).Activate
    ActiveSheet.Range(Cells(startrow, 1), Cells(rangeCount, 16)).PasteSpecial xlPasteAll

    Application.CutCopyMode = False
    Application.CutCopyMode = True
    Workbooks(fl.Name).Close
 End Sub

Upvotes: 0

Related Questions