Hello. A cross-post disclaimer - I created a similar post here yesterday without much traction: https://social.msdn.microsoft.com/F...37308ee/vba-pastespecial-error?forum=exceldev
I will immediately put a link to this post in that Technet MS Forum thread, so that both places will see it is the same post so nobody wastes their time trying to resolve a (hopefully) solved issue.
I have this code which attempts to copy and paste a picture. It gives a sporadic (works error free about 3 / 10 times) error 1004, "PasteSpecial method of Range class failed". Often, if I just debug and click the "play" button to continue the code, it pastes just fine (although this only works sometimes. Others it gets hung up)
I followed EvoAndy and Siddharth Rout's exchange and tried the DoEvents solution, but it did not work: https://social.technet.microsoft.co...4781f98/vba-pastespecial-error?forum=exceldev
Other forums investigating this same issue say to have the code pause so that the Copy method has time to finish, and refer to Chip Pearson's suggestion of Application.Wait http://www.cpearson.com/Excel/WaitFunctions.aspx I added this into the code, but it also did not work.
Any help would be greatly appreciated! Thank you!
I will immediately put a link to this post in that Technet MS Forum thread, so that both places will see it is the same post so nobody wastes their time trying to resolve a (hopefully) solved issue.
I have this code which attempts to copy and paste a picture. It gives a sporadic (works error free about 3 / 10 times) error 1004, "PasteSpecial method of Range class failed". Often, if I just debug and click the "play" button to continue the code, it pastes just fine (although this only works sometimes. Others it gets hung up)
I followed EvoAndy and Siddharth Rout's exchange and tried the DoEvents solution, but it did not work: https://social.technet.microsoft.co...4781f98/vba-pastespecial-error?forum=exceldev
Other forums investigating this same issue say to have the code pause so that the Copy method has time to finish, and refer to Chip Pearson's suggestion of Application.Wait http://www.cpearson.com/Excel/WaitFunctions.aspx I added this into the code, but it also did not work.
Any help would be greatly appreciated! Thank you!
Code:
ElseIf Not Intersect(Target, Range("Appraisers123")) Is Nothing Then
Dim i, j As Long
Dim Arr(2, 1) As Long
Dim sVal As String
Dim sInitials As String
Dim rngQual As Range
Call ToggleAppSettings(False)
'array of row,col pairs representing the paste destination in Range("rptCertSignatures")
Arr(0, 0) = 1
Arr(0, 1) = 1
Arr(1, 0) = 1
Arr(1, 1) = 3
Arr(2, 0) = 6
Arr(2, 1) = 1
With Range("Appraisers123")
For i = 1 To .Cells.Count
sVal = .Cells(i, 1).Value
With wsCert.Range("rptCertSignatures").Cells(Arr(i - 1, 0), Arr(i - 1, 1))
Call DeleteShapesInRange(.Cells(1, 1))
Set rngQual = wsQualifications.Range("Qual" & i & "Anchor")
'have to unhide or pics won't paste into correct spots
Call ToggleShowHideFormat(wsQualifications.Range("rptQual" & i), False)
Call DeleteShapesInRange(rngQual)
If sVal <> "" Then
'copy/paste signature
sInitials = wsInput.Range("Appraiser" & i & "initials").Value2
wsAppraisers.Shapes(sInitials & "Signature").Copy
DoEvents
On Error Resume Next
.PasteSpecial
While Err.Number <> 0 And j < 10
Err.Clear
DoEvents
Application.CutCopyMode = False
wsAppraisers.Shapes(sInitials & "Signature").Copy
Application.Wait Now + TimeSerial(0, 0, 1)
DoEvents
.PasteSpecial
j = j + 1
Debug.Print "paste " & j & ", err = " & Err.Number
Wend
On Error GoTo 0
End If
End With
Next
End With
Call ToggleShowHideFormat(wsCert.Range("rptCertification"), True)
Application.CutCopyMode = False
Target.Parent.Activate
Call ToggleAppSettings(True, True)
Set rngQual = Nothing