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.