• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

I need your help with Copy and Paste VBA Code.

Fred Wayne

Member
Hello. Perhaps my question would sound kind of weird. I want to know why I get an error when I use the copy/paste VBA COde. For example...

Code:
Private Sub CommandButton3_Click()
Set MyData = New DataObject
    MyData.SetText Label2.Caption
    MyData.PutInClipboard
    Unload Me

End Sub

At the beginning it works perfectly and amazing. But for some reason, i don´t know why, it stops working and the paste does not work. Instead of pasting what I want, it only pastes a couple of squares: "￿￿"
After rebooting the PC, enter again to excel and it works perfectly. but after a while it stops pasting what I need and the squares come back. Am I doing something wrong? Is there a failure that can be fixed? What can I do in this case because I can be rebooting my PC at all times.
Thank you in advance.
 
Last edited by a moderator:
There are known problems with the DataObject on Windows 8 or later. You would be well advised to use API calls instead.
See the example.
Module 1 is just to open the form
In module 2 you find the Declarations and Routine to put the text in the clipboard.
The code for your button
Code:
Private Sub CommandButton3_Click()
    putTextInClipboard Label1.Caption
   Unload Me
End Sub
 

Attachments

  • Fred Wayne.xlsm
    24.6 KB · Views: 5
Thank you so much. I have just read your answer. Allow me implement it in my modules and make the corresponding changes in VBA Codes. I will let you know how it is post behavior. Thank for the exquisite explanation.
 
Hello...wow it works perfectly. I have been using excel and I haven´t had to reboot my PC. The new code works and the addition of Declarations have really solved my issue. Once again I do not have words to express m gratitude with your help. You are simply the best. Thank you so much from the bottom of my heart.
 
Back
Top