Ciao Erik, I think the problem is that when you click onto the paste_btn, the
active control becomes the pushbutton itself.
In my opinion is therefore necessary to use a static object which stores the last textbox which has lost the focus, and static variable which stores the cursor position.
To achieve your goal, copy the code below. I have called the destination text box (last active text box) as TextBox2 and used the event routine
TextBox2_Exit. This routine is necessary for each potential destination textbox.
<font face=Courier New><SPAN style="color:#00007F">Public</SPAN> LastActiveTextBox <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
<SPAN style="color:#00007F">Public</SPAN> ActTextBoxCurPos <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> copy_btn_Click()
<SPAN style="color:#00007F">Dim</SPAN> MyData <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
<SPAN style="color:#00007F">Set</SPAN> MyData = <SPAN style="color:#00007F">New</SPAN> DataObject
MyData.SetText txt_tb.SelText
MyData.PutInClipboard
MsgBox MyData.GetText
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> TextBox2_Exit(<SPAN style="color:#00007F">ByVal</SPAN> Cancel <SPAN style="color:#00007F">As</SPAN> MSForms.ReturnBoolean)
<SPAN style="color:#00007F">Set</SPAN> LastActiveTextBox = TextBox2
ActTextBoxCurPos = TextBox2.SelStart
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> paste_btn_Click()
<SPAN style="color:#00007F">Dim</SPAN> MyData <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Object</SPAN>
<SPAN style="color:#00007F">Set</SPAN> MyData = <SPAN style="color:#00007F">New</SPAN> DataObject
MyData.GetFromClipboard
<SPAN style="color:#007F00">''''''' paste in the active textbox (after cursor) '''''''''''''' ????????</SPAN>
<SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> ActTextBoxCurPos
<SPAN style="color:#00007F">Case</SPAN> 0
LastActiveTextBox.Text = MyData.GetText(1)
<SPAN style="color:#00007F">Case</SPAN> Len(LastActiveTextBox)
LastActiveTextBox.Text = LastActiveTextBox.Text & MyData.GetText
<SPAN style="color:#00007F">Case</SPAN> <SPAN style="color:#00007F">Else</SPAN>
LastActiveTextBox.Text = Left(LastActiveTextBox.Text, ActTextBoxCurPos) & MyData.GetText & _
Right(LastActiveTextBox.Text, Len(LastActiveTextBox.Text) - ActTextBoxCurPos)
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
Post for feedback
