Question:
How can I get text selected in an application, say notepad into a vb text box in my application. Then, what about the reverse: if i have text in a text box (i want to use all of it (i.e. not selected) how can I get it to paste into another apps edit box at the current position of the cursor?
Answer:
Cut, copy and paste code is very easy to do. I always provide an Edit menuin my applications and make this code available within the choices. Youare basically using the Clipboard object to transfer data to and from otherapplications or within your own application. Each of these menu items(which are named so that you can figure out what they do) first check thecurrent control to make sure that it is a TextBox control. They then usethe appropriate method of the Clipboard to cut, copy, or paste text to orfrom the control. You can remove the If/Then statement if you wish.ActiveForm is a property of the MDI form which points to the currentlyactive child form within the MDI frame. ActiveControl is the currentlyactive control on that form. You can replace ActiveForm.ActiveControl withthe name of your text box, if you wish.
Private Sub mnEditCopy_Click() If TypeOf ActiveForm.ActiveControl Is TextBox Then Clipboard.SetText ActiveForm.ActiveControl.SelText End IfEnd SubPrivate Sub mnEditCut_Click() If TypeOf ActiveForm.ActiveControl Is TextBox Then Clipboard.SetText ActiveForm.ActiveControl.SelText ActiveForm.ActiveControl.SelText = “” End IfEnd SubPrivate Sub mnEditPaste_Click() If TypeOf ActiveForm.ActiveControl Is TextBox Then ActiveForm.ActiveControl.SelText = Clipboard.GetText End IfEnd SubPrivate Sub mnEditSelectAll_Click() If TypeOf ActiveForm.ActiveControl Is TextBox Then Me.ActiveForm.ActiveControl.SelStart = 1 Me.ActiveForm.ActiveControl.SelLength =Len(ActiveForm.ActiveControl.Text) End IfEnd Sub