Link to home
Start Free TrialLog in
Avatar of neutrinohunter
neutrinohunterFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Copy Text From RichTextBox

I am trying to make a commandbutton (Called Copy) when clicked copy text from a RichTextBox (Called RTB)
But...
A) If no text is selected it selects and copies all the text in the RTB
B) If some text is selected it coped only the selected text.
SOLUTION
Avatar of Djinn_ro
Djinn_ro

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neutrinohunter

ASKER

Sorry I must have been very unclear in my post.

What I meant was I am trying to copy the text from a RichTextBox
But the code I am using seems to work only for textboxes. Thus it aint copying any text.

So if someone could post a code to Copy the text aswell as select the text as Djinn_ro posted that would be gr8

Thx
Avatar of eric0213
eric0213

If RTB.SelLength=0 then
   'no text is select
   YourString=RTB.Text
Else
   'nr of char of selected text
   YourString=RTB.SelText
End if

Clipboard.Clear
Clipboard.SetText = YourString

' If you accept this, give the points to Djinn_ro
k, but what does YourString mean?

I pasted all that in my code, but it says
Variable Not defined?
define the variable...

Dim YourString As String
I tried that.

Its says
Compile Error;
Argument not optional


? Help Please.
what argument?  what line?
This line
Clipboard.SetText = YourString
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There's two choices... one that copies text and one that copies rtf text