Getting "??" when pasting from a TextBox

harveya915

Board Regular
Joined
Sep 4, 2015
Messages
141
I have a few text boxes (4). The contents of those text boxes get copied over to a 5th text box. Then I have a CommandButton that when clicked will copy the contents (to the clipboard), but when I try to paste it to another program all I get is "??". From another thread I learned that it's because I'm copying unicode characters. Here's what I have:
VBA Code:
Private Sub CommandButton2_Click()

Dim dataObj As MSForms.DataObject
    Set dataObj = New MSForms.DataObject
  
    With dataObj
        .SetText TextBox5.Value
        .PutInClipboard
    End With
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
My understanding is that this is a bug that has to do with Windows Explorer. According to MVP Rory Archibald (User handle: RoryA on this forum), it started in Windows 8 has continued through to Windows 10 (link). It occurs regardless of whether you're copying unicode characters or not - it happened to me this even when I was testing a routine to clear the dataobject clipboard (I ended up having to use an API instead).

I once read that it will be resolved if you happen to close down all the open explorer windows (I think, by extension, you should also close any Internet Explorer windows) - I remember trying it a few times, and it working on each occasion.

As alternatives, you can use APIs to copy to / paste from the clipboard. Or, for the 'cheap-and-nasty' option, there are these three functions:
VBA Code:
Sub SetClipBoardText(ByVal Text As Variant)
    On Error Resume Next
    CreateObject("htmlfile").ParentWindow.ClipboardData.SetData "Text", Text
End Sub
Function GetClipBoardText() As String
    On Error Resume Next
    GetClipBoardText = CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("Text")
End Function
Sub ClearClipBoardText()
    On Error Resume Next
    CreateObject("htmlfile").ParentWindow.ClipboardData.clearData "Text"
End Sub

I say 'cheap-and-nasty' because it's a bit inefficient and slow and not really what they were designed for - but I just really love one-line procedures! I can get you the API equivalents, though, if you'd prefer.

So in the context of your code:
VBA Code:
Private Sub CommandButton2_Click()
SetClipBoardText TextBox5.Value

Dim GetMyText As String
GetMyText = GetClipBoardText
MsgBox GetMyText
End Sub
 
Upvote 0
Interesting. I have personally never experienced this problem before not in Windows7 x32bit not now in Windows 10 Pro x64bit build 19043.1889.
Even when I have file explorer windows open, the msforms dataobject seems consistent and works fine.

I was first made aware of this bug by Jon Peltier the other day
 
Upvote 0
Interesting. I have personally never experienced this problem before not in Windows7 x32bit not now in Windows 10 Pro x64bit build 19043.1889.
Even when I have file explorer windows open, the msforms dataobject seems consistent and works fine.

I was first made aware of this bug by Jon Peltier the other
It doesn't happen to me all the time, but it does on occasion. No idea what this bug is though.
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,945
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top