PDA

View Full Version : Sleeper: Copy and paste in userform textbox



gibbo1715
03-27-2005, 09:07 AM
can anyone help with this please

I want a button that mimics the shortcut ctrl - c and ctrl - v (copy/paste) that I can use to copy into a textbox on a userform from another application, is there an easy way to do this?

Note: i dont want this to be via a right click on the mouse please and do need it to be code for a button

Many Thanks

Gibbo

Killian
03-27-2005, 09:45 AM
Hi Gibbo,
I'm not sure what you mean. Do you already have something on the clipboard you want to put in a text box or do you have a value in another app somewhere you need to show in it?
Normally, to assign it directly, you would use something like


TextBox1.Text = Range("A1").Value

in the Commandbutton_Click event
If you're controlling another app, you might need to assign your value to a variable and pass that to the control (or make it public so the userform code can see it too)
You can of course use the copy and paste methods e.g.


Range("A1").Copy
TextBox1.Paste

the only thing you have to watch here is to maybe check the clipboard contents is a string or the textbox paste method will error. Also, as in the example here, you will probably get a paragraph character at the end which you might want to strip out