3

I am using the following code to copy text to the clipboard for the user to paste afterwards:

Sub CopyText(ByVal StringToCopy As String)
    Dim D As DataObject
    Set D = New DataObject
    With D
       .SetText StringToCopy 
       .PutInClipboard
    End With
    Set D = Nothing
End Sub

It worked fine for a long time on multiple machines. It stopped working in the past few month. Instead of returning copied text it returns two unknown characters that show up as ?? in the immediate pane or character 63 if I run ?Asc(.GetText) which according to this answer means text is not recognized. The string is lost after .PutInClipboard:

.SetText "Test"
Debug.Print .GetText `returns "Test"
.PutInClipboard
Debug.Print .GetText `returns "??"

The only solution I have found so far suggests using API calls, which I would like not to do if possible.

Edit: after following up on the thread from msdn is appears that the issue is reproduced if the File Explorer is open.

Victor K
  • 1,049
  • 2
  • 10
  • 21
  • 1
    [The second answer](https://social.msdn.microsoft.com/Forums/en-US/48e8c30c-24ee-458e-a873-a4e6e13f5926/dataobject-settext-and-putinclipboard-sequence-puts-invalid-data-hex-63-characters-in-clipboard) is the only thing I have found to work. It's fairly trivial though, only detriment is that it takes up text in your module. – jclasley Jan 24 '20 at 14:21
  • 3
    @jclasley after looking further in the discussion in the linked thread it appears that the issue only shows up if file explorer is open. – Victor K Jan 24 '20 at 14:29

0 Answers0