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

前端 未结 3 736
广开言路
广开言路 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条回答
  •  Happy的楠姐
    2021-01-27 14:00

    Just wanted to let everyone know I have found a (sort of) solution. Based on the answers/comments from Tim Williams and PeterT I modified the code to look like this:

    Sub CopyAllShapes()
    Dim ws As Worksheet
    
    ' Sets the non-generated worksheets as an array
    nSheets = Array("EXAMPLE", "Weekly Totals", "Menu")
    
    ' Copies the Picture from the EXAMPLE sheet to all worksheets not in the array and then assigns a 
    ' seperate Macro called "Export" to the picture on each of these sheets.
    For Each ws In ActiveWorkbook.Worksheets
        If Not IsNumeric(Application.Match(ws.Name, nSheets,0)) Then
            Sheets("EXAMPLE").Shapes("Picture 1").Copy
        On Error Resume Next
            ws.Range("J62").PasteSpecial
        On Error Goto 0
            ws.Shapes("Picture 1").OnAction = "Export"
        End If
    Next ws
    
    Application.CutCopyMode = xlCopy
    End Sub
    

    This has successfully ignored the error and everything is working properly now! Thanks everyone for your help, hopefully this aids someone else in the future!

提交回复
热议问题