Clipboard not holding entire textbox contents

MichiganWilliams

New Member
Joined
Jan 15, 2017
Messages
12
Hello,

I'm not very experienced and have searched and read through tutorials. I've got a textbox2 on sheet2. It's a large textbox with a lot of text that may get entered.

Not everyone that uses this will be tech savvy (to select, ctrl C themselves) so I created a command button to copy the text from the textbox to the clipboard (see below). However, when I paste the contents of the clipboard into notepad or word or any other application, only the first 1023 characters from the textbox actually got put in the clipboard. Am I missing something obvious?

Code:
Private Sub CommandButton3_Click()    Application.SendKeys ("^c~")
    InputBox "clipboard", , Sheets("Sheet2).TextBox2.Value
End Sub

I tried a few other methods of copying to the clipboard but none of them were copying any text to the clipboard. I couldn't figure out what I was doing wrong... Like the following (no errors, just nothing gets copied)
Code:
[COLOR=#101094][FONT=inherit]Private[/FONT][/COLOR][COLOR=#303336][FONT=inherit] [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CommandButton3_Click[/FONT][/COLOR][COLOR=#303336][FONT=inherit]()[/FONT][/COLOR]<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">[COLOR=#303336][FONT=inherit]    [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] MyData [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#303336][FONT=inherit] [/FONT][/COLOR][COLOR=#101094][FONT=inherit]New[/FONT][/COLOR][COLOR=#303336][FONT=inherit] DataObject
    MyData[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]SetText TextBox2[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Text
    MyData[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]PutInClipboard [/FONT][/COLOR]</code>[COLOR=#101094][FONT=inherit]End[/FONT][/COLOR][COLOR=#303336][FONT=inherit] [/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR]

Thanks for your help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Just in case anyone searches this in the future. I found out why the code did not work. Apparently there's a bug that if you have a windows explorer open to the C drive, dataobjects do not work. I randomly found this in another forum and noticed I did have a windows explorer window open. I closed it and magically everything started working. Totally bizarre.
Code:
With New MSForms.DataObject        .SetText TextBox2.Text
        .PutInClipboard
    End With
 
Upvote 0
Hello,

I'm not very experienced and have searched and read through tutorials. I've got a textbox2 on sheet2. It's a large textbox with a lot of text that may get entered.

Not everyone that uses this will be tech savvy (to select, ctrl C themselves) so I created a command button to copy the text from the textbox to the clipboard (see below). However, when I paste the contents of the clipboard into notepad or word or any other application, only the first 1023 characters from the textbox actually got put in the clipboard. Am I missing something obvious?

Code:
Private Sub CommandButton3_Click()    Application.SendKeys ("^c~")
    InputBox "clipboard", , Sheets("Sheet2).TextBox2.Value
End Sub

I tried a few other methods of copying to the clipboard but none of them were copying any text to the clipboard. I couldn't figure out what I was doing wrong... Like the following (no errors, just nothing gets copied)
Code:
[COLOR=#101094][FONT=inherit]Private[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR][COLOR=#303336][FONT=inherit] CommandButton3_Click[/FONT][/COLOR][COLOR=#303336][FONT=inherit]()[/FONT][/COLOR]<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">[COLOR=#101094][FONT=inherit]Dim[/FONT][/COLOR][COLOR=#303336][FONT=inherit] MyData [/FONT][/COLOR][COLOR=#101094][FONT=inherit]As[/FONT][/COLOR][COLOR=#101094][FONT=inherit]New[/FONT][/COLOR][COLOR=#303336][FONT=inherit] DataObject
    MyData[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]SetText TextBox2[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Text
    MyData[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]PutInClipboard [/FONT][/COLOR]</code>[COLOR=#101094][FONT=inherit]End[/FONT][/COLOR][COLOR=#101094][FONT=inherit]Sub[/FONT][/COLOR]

Thanks for your help.

Your second code should work.

Code:
Sub test()
    Dim MyData As New DataObject
    With MyData
        .SetText TextBox1.Text, 1
        .PutInClipboard
        .GetFromClipboard
        MsgBox Len(MyData.GetText(1))
    End With
End Sub
 
Upvote 0
Just in case anyone searches this in the future. I found out why the code did not work. Apparently there's a bug that if you have a windows explorer open to the C drive, dataobjects do not work. I randomly found this in another forum and noticed I did have a windows explorer window open. I closed it and magically everything started working. Totally bizarre.
Code:
With New MSForms.DataObject        .SetText TextBox2.Text
        .PutInClipboard
    End With


Strange! I have two windows explorers open and the code run fine.

Anyway, glad you got this sorted.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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