-
I Have been trying for ages to get a copy and paste function to work in my application, but I just cant figure out how to do it! All I want to do is highlight something in one of my text boxes, go to the edit menu, click on copy and then paste the data into a new text box using the edit menu, but its proving very annoying and difficult. Can any of you help me??
-
Hi. I experimented with this for a few minutes and the following will allow you to copy text from one textbox to the clipboard and then paste that text into another textbox. The Clipboard object is shared by all Windows applications, so no need to declare it in VB.
Code:
Option Explicit
Private Sub CmdCopy_Click()
Clipboard.Clear
Clipboard.SetText (Text1.SelText)
End Sub
Private Sub CmdPaste_Click()
Text2 = Clipboard.GetText
End Sub
Maybe it will give you a starting point to work from.
-
<?>
'From textbox to textbox you don't need copy 'n' paste
Code:
Private Sub Command1_Click()
'paste it at the end of text2.text
'could be anywhere you want or overwrite
Text2.SelStart = Len(Text2.Text)
Text2.Text = Text2.Text & " " & Text1.SelText
End Sub
Private Sub Form_Load()
Text1.Text = "Mary Lou"
Text2.Text = "Hello"
End Sub
-
Try This
Put a menu up (Edit) subitems Copy, Paste
Place two textboxes on form
Private Sub mCopy_Click()
If Me.ActiveControl.Name Like "Text*" Then
Clipboard.Clear
Clipboard.SetText Me.ActiveControl.Text
End If
End Sub
Private Sub mPaste_Click()
If Me.ActiveControl.Name Like "Text*" Then
Me.ActiveControl.Text = Clipboard.GetText
End If
End Sub
-
You should check to see if text is highlighted as well.
Code:
Private Sub CmdCopy_Click()
If Text1.SelText <> "" Then
Clipboard.Clear
Clipboard.SetText (Text1.SelText)
End If
End Sub
But as Wayne (HeSaidJoe) said, you don't need copy and paste to put something from one textbox to the other.