Copy textbox contents with Excel VBA?

  Simsy 12:41 16 Feb 05
Locked

Hi folks,

I've simplified this problem to the basics.

I have a user form in Excel, (2000). It displays some text in a textbox

I want to copy the contents, (to the Windows clipboard), of the textbox using a button.

The textbox is called txtTIP and I have the following code with the Click event of the button;

txtTIP.Copy

This doesn't seem to work, unless I have previously selected the contents of the textbox. I can't seem to work out how to do this in VBA.

Can anyone advise?

Thanks in advance.

Regards,

Simsy

  VoG II 12:44 16 Feb 05

txtTIP.Select

txtTIP.Copy

should work.

  Simsy 12:58 16 Feb 05

tried that VoG™, and get the error message;

Compile error.
Argument not optional.

and it the .Select that appears highlighted.


There is a .selText option that appears from the dropdown after typing the "." but that results in the error message

Compile error.
Invalid use of property.


I'm using Excel2000 on win98se, in case that's relevant?


Any more suggestions?

Thanks,

Regards.

Simsy

  VoG II 13:02 16 Feb 05

ActiveSheet.Shapes(txtTIP).Select

Selection.Copy

  VoG II 13:03 16 Feb 05

Or if txtTIP is not declared as a variable

ActiveSheet.Shapes("txtTIP").Select

  Simsy 13:11 16 Feb 05

but that's not working either, I think becasue the textbox isn't on a sheet, but on a form.

I need to log off now, bu ti'd welcome any more suggestions!

Regards,

Simsy

  VoG II 13:30 16 Feb 05

I can't get the Copy to work either. However this works if a little untidy:

Sub tst2()

Dim txt As String

txt = UserForm1.TextBox1.Value

Range("A1").Value = txt

Range("A1").Cut

End Sub

The text in A1 will disappear when the text is pasted elsewhere.

  rogertjj 14:56 16 Feb 05

If you type :


Application.CutCopyMode = xlCopy


before you try and copy the text, it should work

  rogertjj 14:58 16 Feb 05

Sorry, ignore me. This only works if the text in the textbox is already selected !!

  rogertjj 15:10 16 Feb 05

click here may help ?

I found the following code in MrExcel posted by DK and I quote:

"You can use the DataObject provided by the MS Forms library. For example, say you have a textbox called TextBox1 and a command button named cmdCopy this code will copy the contents of the textbox to the clipboard."

++++++++++++++++++++++++++++++++++++++

Private Sub cmdCopy_Click()

Dim YourDataObject As DataObject

If Me.TextBox1.Text <> "" Then

Set YourDataObject = New DataObject

YourDataObject.SetText Me.TextBox1.Text

YourDataObject.PutInClipboard

End If

End Sub

++++++++++++++++++++++++++++++++++++++

Yet another element to add to my growing list of things to learn. Once the form is hidden then you can paste the result manually wherever you wish.

This thread is now locked and can not be replied to.

Best phone camera 2016/2017: Galaxy S7 vs iPhone 7 vs Google Pixel vs HTC 10 Evo vs OnePlus 3T vs…

1995-2015: How technology has changed the world in 20 years

These are the Best Christmas Ads and Studio Projects of 2016

Super Mario Run preview | Hands-on first impressions of Super Mario Run: Mario's iPhone & iPad…