'Runtime Error 1004 "Can't find the Paste property for the Pictures Class"

I have several script that have a part that is copying Charts and Pasting it in an area as Picture. Those scripts are working without any error when I look at them running but when they run automaticaly, with Windows Scheduler then it fails everytime with Paste Property Error. I have read everywhere to make it work, made changes as sending "up" and "down" key to wake up clipboard, copying and pasting without selecting, adding a waiting time in a loop to be sure the information get to and from Clipboard, but nothing helps. Has anyone seen such error before and found a solution?

Thanks.



Solution 1:[1]

As I haven't got any answer I have worked on it and tried and tried several ways to avoid that error when windows is locked and I think I have got good answer and solution, so I post it here so if someone else got same troubles, he doesn't need to go through all the tests. The problem I see is that when you use .Chart.CopyPicture when Windows is Locked is not easy to get a Paste after it, as this use the Office Clipboard. After the CopyPicture you can get 2 errors that stop the Paste process, the first one is related to the time to process the Copy / Paste between Excel and Office Clipboard and the second one is that no other focus has to come in between the Copy and the Paste. When those 2 rules are followed, the errors are not showing up. Here is my final code:

        application.SendKeys "{UP}"
        application.SendKeys "{DOWN}"
        Sheet_(4).ChartObjects("Diagram 1").Chart.CopyPicture
        Time1 = Now
        Time2 = Now + TimeValue("00:00:10")
        Do Until Time1 >= Time2
            DoEvents
            Time1 = Now
        Loop
        ErrorPlace = "Paste_1"
        On Error GoTo Handle_Wait
Paste_1:
        Sheet_(3).Paste Destination:=Sheet_(3).Range("B6"), Link:=False
        On Error GoTo Handle

As you can see, I first SendKey to be sure that Office Clipboard is waked up, then I copy as picture and wait 10 seconds to be sure the picture is ready to be used, then I register a new Error Handle where I have a new wait loop, if needed, and paste the picture. Never in between Copy and Paste I have any Select or Activate to avoid swifting focus. This solution has worked several days now, so it feels good. I hope this can help other who got such problem. Thanks.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ManuSwe