Run-time error '1004': Microsoft Excel cannot paste the data

前端 未结 3 663
广开言路
广开言路 2021-01-27 13:30

I have looked up the question and have seen several solutions addressing things like Select or having protected worksheets, none of which apply to me here.

For various

3条回答
  •  一个人的身影
    2021-01-27 14:00

    On moving to Office 365 and Win10 (can't say which of those was the culprit) I found a bunch of existing macros which would give that same error when trying to paste a copied image onto a worksheet.

    When entering debug, the "paste" line would be highlighted, but if I hit "Continue" it would (after one or two attempts) run with no errors.

    I ended up doing this:

    'paste problem fix
    Sub PastePicRetry(rng As Range)
        Dim i As Long
        Do While i < 20
            On Error Resume Next
            rng.PasteSpecial
            If Err.Number <> 0 Then
                Debug.Print "Paste failed", i
                DoEvents
                i = i + 1
            Else
                Exit Do
            End If
            On Error GoTo 0
            i = i + 1
        Loop
    End Sub
    

    ...which looks like overkill but was the only reliable fix for the problem.

    EDIT: cleaned up and refactored into a standalone sub.

提交回复
热议问题