vaniificat
New Member
- Joined
- Feb 22, 2011
- Messages
- 3
Hello,
I've been using a certain subroutine to copy and paste the values of particular cells from Excel into a different program, and until recently this has been working fantastically. But now, all of a sudden, when I try to run this sub on certain cells, I get this error: "-2147221040 (800401D0) - OpenClipboard Failed". I call the copy-and-paste sub on a lot of different cells in various macros, but for some reason the error is always thrown on the third line:
I don't think it's an issue of increasing the sleep time, because it's never needed it in the past. Here's the derivative sub ("CP", short for "copy-paste"):
The only thing I can think of is that something I changed in another macro somewhere could be conflicting with normal clipboard functioning - but I don't know why that would be. The main thing I changed was that I went from manual macro calling (clicking on the ribbon) to a visual, checkbox-and-button based interface.
Also, as another fun fact, the cells the copy-paste sub throws an error on almost always end up getting deleted (presumably by the sub itself). That's also never happened before, and I don't understand why an error like that would only just manifest itself now.
Thanks for any insight you might be able to provide.
I've been using a certain subroutine to copy and paste the values of particular cells from Excel into a different program, and until recently this has been working fantastically. But now, all of a sudden, when I try to run this sub on certain cells, I get this error: "-2147221040 (800401D0) - OpenClipboard Failed". I call the copy-and-paste sub on a lot of different cells in various macros, but for some reason the error is always thrown on the third line:
Code:
Public Sub VeryFirstPartOfOneOfMySubs(
CP ("$CB$3") 'This works fine
Sleep (100)
CP ("$BA$16") 'The error shows up here
Sleep (50)
...
End Sub
I don't think it's an issue of increasing the sleep time, because it's never needed it in the past. Here's the derivative sub ("CP", short for "copy-paste"):
Code:
Private Sub CP(Rnge As String)
Dim MyData As New MSForms.DataObject
MyData.SetText Range(Rnge).Value
MyData.PutInClipboard 'The error shows up here
RC 'Short for "right-click"; simulates a right-click in another app to paste
Sleep (50)
End Sub
The only thing I can think of is that something I changed in another macro somewhere could be conflicting with normal clipboard functioning - but I don't know why that would be. The main thing I changed was that I went from manual macro calling (clicking on the ribbon) to a visual, checkbox-and-button based interface.
Also, as another fun fact, the cells the copy-paste sub throws an error on almost always end up getting deleted (presumably by the sub itself). That's also never happened before, and I don't understand why an error like that would only just manifest itself now.
Thanks for any insight you might be able to provide.
Last edited: