Hello all,
I have a form which contains a number of textboxes and other such objects. Within this form I have a listbox which is displayed when the right-mouse is clicked. This list displays the options "Copy" and "Paste". The problem is that I cannot seem to code the right functions for these options.
I have tried using SendKeys. The copy function works fine, however when I use SendKeys for paste it will only ever paste into the first textbox as defined by the tab order, which of course renders the function useless.
I found an alternative which is the DataObject PutInClipboard and GetFromClipboard but the copy source and target objects are coded rather than user selectable. The code follows:
Dim MyData As DataObject
Private Sub ListBox1_Click()
If ListBox1.Value = "Copy" Then
Set MyData = New DataObject
MyData.SetText TextBox1.Text <<
MyData.PutInClipboard
ElseIf ListBox1.Value = "Paste" Then
Set MyData = New DataObject
MyData.GetFromClipboard
TextBox2.Text = MyData.GetText(1) <<
End If
ListBox1.Visible = False
End Sub
The problem is the use of TextBox1.Text and TextBox2.Text (I've used << to indicate this). These need to be variable depending on what box the user has called the listbox from.
Any help appreciated!
Start Free Trial